|
| 1 | +/** |
| 2 | + * OpenTok Java SDK |
| 3 | + * Copyright (C) 2023 Vonage. |
| 4 | + * http://www.tokbox.com |
| 5 | + * |
| 6 | + * Licensed under The MIT License (MIT). See LICENSE file for more information. |
| 7 | + */ |
| 8 | +package com.opentok; |
| 9 | + |
| 10 | +/** |
| 11 | + * Defines values for the <code>properties</code> parameter of the |
| 12 | + * {@link OpenTok#startCaptions(String, String, CaptionProperties)} method. |
| 13 | + * |
| 14 | + * @see OpenTok#startCaptions(String, String, CaptionProperties) |
| 15 | + */ |
| 16 | +public class CaptionProperties { |
| 17 | + private final String statusCallbackUrl, languageCode; |
| 18 | + private final int maxDuration; |
| 19 | + private final boolean partialCaptions; |
| 20 | + |
| 21 | + private CaptionProperties(Builder builder) { |
| 22 | + statusCallbackUrl = builder.statusCallbackUrl; |
| 23 | + languageCode = builder.languageCode; |
| 24 | + maxDuration = builder.maxDuration; |
| 25 | + partialCaptions = builder.partialCaptions; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * A publicly reachable URL controlled by the customer and capable of generating the content to |
| 30 | + * be rendered without user intervention. The minimum length of the URL is 15 characters and the |
| 31 | + * maximum length is 2048 characters. For more information, see |
| 32 | + * <a href=https://tokbox.com/developer/guides/live-captions/#live-caption-status-updates> |
| 33 | + * Live Caption status updates</a>. |
| 34 | + * |
| 35 | + * @return The status callback URL as a string, or {@code null} if not set. |
| 36 | + */ |
| 37 | + public String getStatusCallbackUrl() { |
| 38 | + return statusCallbackUrl; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * The BCP-47 code for a spoken language used on this call. |
| 43 | + * |
| 44 | + * @return The language code as a string. |
| 45 | + */ |
| 46 | + public String getLanguageCode() { |
| 47 | + return languageCode; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * The maximum duration for the audio captioning, in seconds. |
| 52 | + * |
| 53 | + * @return The maximum captioning duration as an integer. |
| 54 | + */ |
| 55 | + public int getMaxDuration() { |
| 56 | + return maxDuration; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Whether faster captioning is enabled at the cost of some degree of inaccuracies. |
| 61 | + * |
| 62 | + * @return {@code true} if the partial captions setting is enabled. |
| 63 | + */ |
| 64 | + public boolean partialCaptions() { |
| 65 | + return partialCaptions; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Entry point for constructing an instance of this class. |
| 70 | + * |
| 71 | + * @return A new Builder. |
| 72 | + */ |
| 73 | + public static Builder Builder() { |
| 74 | + return new Builder(); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Used to create a CaptionProperties object. |
| 79 | + * |
| 80 | + * @see CaptionProperties |
| 81 | + */ |
| 82 | + public static class Builder { |
| 83 | + private String languageCode = "en-US", statusCallbackUrl; |
| 84 | + private int maxDuration = 14400; |
| 85 | + private boolean partialCaptions = true; |
| 86 | + |
| 87 | + private Builder() { |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * The BCP-47 code for a spoken language used on this call. The default value is "en-US". The following |
| 92 | + * language codes are supported: "en-AU" (English, Australia), "en-GB" (Englsh, UK), "es-US" (English, US), |
| 93 | + * "zh-CN" (Chinese, Simplified), "fr-FR" (French), "fr-CA" (French, Canadian), "de-DE" (German), |
| 94 | + * "hi-IN" (Hindi, Indian), "it-IT" (Italian), "ja-JP" (Japanese), "ko-KR" (Korean), |
| 95 | + * "pt-BR" (Portuguese, Brazilian), "th-TH" (Thai). |
| 96 | + * |
| 97 | + * @param languageCode The BCP-47 language code as a string. |
| 98 | + * |
| 99 | + * @return This Builder with the languageCode property setting. |
| 100 | + */ |
| 101 | + public Builder languageCode(String languageCode) { |
| 102 | + if (languageCode == null || languageCode.length() != 5 || languageCode.charAt(2) != '-') { |
| 103 | + throw new IllegalArgumentException("Invalid language code."); |
| 104 | + } |
| 105 | + this.languageCode = languageCode; |
| 106 | + return this; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * A publicly reachable URL controlled by the customer and capable of generating the content to |
| 111 | + * be rendered without user intervention. The minimum length of the URL is 15 characters and the |
| 112 | + * maximum length is 2048 characters. For more information, see |
| 113 | + * <a href=https://tokbox.com/developer/guides/live-captions/#live-caption-status-updates> |
| 114 | + * Live Caption status updates</a>. |
| 115 | + * |
| 116 | + * @param statusCallbackUrl The status callback URL as a string. |
| 117 | + * |
| 118 | + * @return This Builder with the statusCallbackUrl property setting. |
| 119 | + */ |
| 120 | + public Builder statusCallbackUrl(String statusCallbackUrl) { |
| 121 | + if (statusCallbackUrl == null || statusCallbackUrl.length() < 15 || statusCallbackUrl.length() > 2048) { |
| 122 | + throw new IllegalArgumentException("Status callback URL must be between 15 and 2048 characters."); |
| 123 | + } |
| 124 | + this.statusCallbackUrl = statusCallbackUrl; |
| 125 | + return this; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
| 129 | + * The maximum duration for the audio captioning, in seconds. |
| 130 | + * The default value is 14,400 seconds (4 hours), the maximum duration allowed. |
| 131 | + * |
| 132 | + * @param maxDuration The maximum captions duration in seconds. |
| 133 | + * |
| 134 | + * @return This Builder with the maxDuration property setting. |
| 135 | + */ |
| 136 | + public Builder maxDuration(int maxDuration) { |
| 137 | + if ((this.maxDuration = maxDuration) < 0 || maxDuration > 14400) { |
| 138 | + throw new IllegalArgumentException("Max duration must be positive and less than 14400 seconds."); |
| 139 | + } |
| 140 | + return this; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Whether to enable this to faster captioning at the cost of some degree of inaccuracies. |
| 145 | + * The default value is {@code true}. |
| 146 | + * |
| 147 | + * @param partialCaptions Whether to enable faster captions. |
| 148 | + * |
| 149 | + * @return This Builder with the partialCaptions property setting. |
| 150 | + */ |
| 151 | + public Builder partialCaptions(boolean partialCaptions) { |
| 152 | + this.partialCaptions = partialCaptions; |
| 153 | + return this; |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Builds the CaptionProperties object. |
| 158 | + * |
| 159 | + * @return The CaptionProperties object with this builder's settings. |
| 160 | + */ |
| 161 | + public CaptionProperties build() { |
| 162 | + return new CaptionProperties(this); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
0 commit comments