@@ -110,9 +110,9 @@ public List<String> getSupportedModels() {
110110 }
111111
112112 /**
113- * Generates speech from text using the support models.
113+ * Generates speech using advanced audio models.
114114 *
115- * You can save the returned byte to audio file using FileOutputStream("path/audio.mp3").
115+ * You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
116116 *
117117 * @param input SpeechInput object containing the text and gender to use.
118118 * @return byte array of the decoded audio content.
@@ -121,7 +121,101 @@ public List<String> getSupportedModels() {
121121 public byte [] generateEnglishText (Text2SpeechInput input ) throws IOException {
122122
123123 if (this .keyType == SpeechModels .google ) {
124- return this .generateGoogleText (input .getText (), input .getGender (), "en-gb" );
124+ return this .generateGoogleText (input .getText (), input .getGender (), "en-GB" );
125+ } else {
126+ throw new IllegalArgumentException ("the keyType not supported" );
127+ }
128+ }
129+
130+
131+ /**
132+ * Generates speech using advanced audio models.
133+ *
134+ * You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
135+ *
136+ * @param input SpeechInput object containing the text and gender to use.
137+ * @return byte array of the decoded audio content.
138+ * @throws IOException in case of communication error.
139+ */
140+ public byte [] generateMandarinText (Text2SpeechInput input ) throws IOException {
141+
142+ if (this .keyType == SpeechModels .google ) {
143+ return this .generateGoogleText (input .getText (), input .getGender (), "cmn-CN" );
144+ } else {
145+ throw new IllegalArgumentException ("the keyType not supported" );
146+ }
147+ }
148+
149+ /**
150+ * Generates speech using advanced audio models.
151+ *
152+ * You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
153+ *
154+ * @param input SpeechInput object containing the text and gender to use.
155+ * @return byte array of the decoded audio content.
156+ * @throws IOException in case of communication error.
157+ */
158+ public byte [] generateArabicText (Text2SpeechInput input ) throws IOException {
159+
160+ if (this .keyType == SpeechModels .google ) {
161+ return this .generateGoogleText (input .getText (), input .getGender (), "ar-XA" );
162+ } else {
163+ throw new IllegalArgumentException ("the keyType not supported" );
164+ }
165+ }
166+
167+
168+ /**
169+ * Generates speech using advanced audio models.
170+ *
171+ * You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
172+ *
173+ * @param input SpeechInput object containing the text and gender to use.
174+ * @return byte array of the decoded audio content.
175+ * @throws IOException in case of communication error.
176+ */
177+ public byte [] generateTurkishText (Text2SpeechInput input ) throws IOException {
178+
179+ if (this .keyType == SpeechModels .google ) {
180+ return this .generateGoogleText (input .getText (), input .getGender (), "tr-TR" );
181+ } else {
182+ throw new IllegalArgumentException ("the keyType not supported" );
183+ }
184+ }
185+
186+ /**
187+ * Generates speech using advanced audio models.
188+ *
189+ * You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
190+ *
191+ * @param input SpeechInput object containing the text and gender to use.
192+ * @param langCode the language code, make sure to use the right code for the model engine.
193+ * @return byte array of the decoded audio content.
194+ * @throws IOException in case of communication error.
195+ */
196+ public byte [] generateText (Text2SpeechInput input , String langCode ) throws IOException {
197+
198+ if (this .keyType == SpeechModels .google ) {
199+ return this .generateGoogleText (input .getText (), input .getGender (), langCode );
200+ } else {
201+ throw new IllegalArgumentException ("the keyType not supported" );
202+ }
203+ }
204+
205+
206+ /**
207+ * Generates speech using advanced audio models.
208+ *
209+ * You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
210+ *
211+ * @param input SpeechInput object containing the text and gender to use.
212+ * @return byte array of the decoded audio content.
213+ * @throws IOException in case of communication error.
214+ */
215+ public byte [] generateGermanText (Text2SpeechInput input ) throws IOException {
216+
217+ if (this .keyType == SpeechModels .google ) {
218+ return this .generateGoogleText (input .getText (), input .getGender (), "de-de" );
125219 } else {
126220 throw new IllegalArgumentException ("the keyType not supported" );
127221 }
@@ -143,13 +237,56 @@ private byte[] generateGoogleText(String text, Gender gender, String language) t
143237 params .put ("text" , text );
144238 params .put ("languageCode" , language );
145239
146- if (gender == Gender .FEMALE ) {
147- params .put ("name" , "en-GB-Standard-A" );
148- params .put ("ssmlGender" , "FEMALE" );
149- } else {
150- params .put ("name" , "en-GB-Standard-B" );
151- params .put ("ssmlGender" , "MALE" );
152- }
240+ language = language .toLowerCase ();
241+
242+ if (language .equals ("en-gb" )) {
243+ // English
244+ if (gender == Gender .FEMALE ) {
245+ params .put ("name" , "en-GB-Standard-A" );
246+ params .put ("ssmlGender" , "FEMALE" );
247+ } else {
248+ params .put ("name" , "en-GB-Standard-B" );
249+ params .put ("ssmlGender" , "MALE" );
250+ }
251+ } else if (language .equals ("tr-tr" )) {
252+ // Turkish
253+ if (gender == Gender .FEMALE ) {
254+ params .put ("name" , "tr-TR-Standard-A" );
255+ params .put ("ssmlGender" , "FEMALE" );
256+ } else {
257+ params .put ("name" , "tr-TR-Standard-B" );
258+ params .put ("ssmlGender" , "MALE" );
259+ }
260+ } else if (language .equals ("cmn-cn" )) {
261+ // Mandarin Chinese
262+ if (gender == Gender .FEMALE ) {
263+ params .put ("name" , "cmn-CN-Standard-A" );
264+ params .put ("ssmlGender" , "FEMALE" );
265+ } else {
266+ params .put ("name" , "cmn-CN-Standard-B" );
267+ params .put ("ssmlGender" , "MALE" );
268+ }
269+ } else if (language .equals ("de-de" )) {
270+ // German (Germany)
271+ if (gender == Gender .FEMALE ) {
272+ params .put ("name" , "de-DE-Standard-A" );
273+ params .put ("ssmlGender" , "FEMALE" );
274+ } else {
275+ params .put ("name" , "de-DE-Standard-B" );
276+ params .put ("ssmlGender" , "MALE" );
277+ }
278+ } else if (language .equals ("ar-xa" )) {
279+ // Arabic
280+ if (gender == Gender .FEMALE ) {
281+ params .put ("name" , "ar-XA-Wavenet-A" );
282+ params .put ("ssmlGender" , "FEMALE" );
283+ } else {
284+ params .put ("name" , "ar-XA-Standard-B" );
285+ params .put ("ssmlGender" , "MALE" );
286+ }
287+ } else {
288+ throw new IllegalArgumentException ("Unsupported language code: " + language );
289+ }
153290
154291 AudioResponse resModel = (AudioResponse ) wrapper .generateSpeech (params );
155292 decodedAudio = AudioHelper .decode (resModel .getAudioContent ());
0 commit comments