Skip to content

Commit 8d81e2d

Browse files
committed
chore(TTS): Generate text to speech
1 parent 41699ea commit 8d81e2d

File tree

1 file changed

+95
-47
lines changed

1 file changed

+95
-47
lines changed

watson_developer_cloud/text_to_speech_v1.py

Lines changed: 95 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_voice(self, voice, customization_id=None, **kwargs):
111111
obtain information for that custom voice model of the specified voice. To list
112112
information about all available voices, use the **List voices** method.
113113
**See also:** [Specifying a
114-
voice](https://console.bluemix.net/docs/services/text-to-speech/http.html#voices).
114+
voice](/docs/services/text-to-speech/http.html#voices).
115115
116116
:param str voice: The voice for which information is to be returned.
117117
:param str customization_id: The customization ID (GUID) of a custom voice model
@@ -150,7 +150,7 @@ def list_voices(self, **kwargs):
150150
name, language, gender, and other details about the voice. To see information
151151
about a specific voice, use the **Get a voice** method.
152152
**See also:** [Specifying a
153-
voice](https://console.bluemix.net/docs/services/text-to-speech/http.html#voices).
153+
voice](/docs/services/text-to-speech/http.html#voices).
154154
155155
:param dict headers: A `dict` containing the request headers
156156
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
@@ -179,27 +179,78 @@ def synthesize(self,
179179
"""
180180
Synthesize audio.
181181
182-
Synthesizes text to spoken audio, returning the synthesized audio stream as an
183-
array of bytes. You can pass a maximum of 5 KB of text. Use the `Accept` header
184-
or the `accept` query parameter to specify the requested format (MIME type) of the
185-
response audio. By default, the service uses `audio/ogg;codecs=opus`.
186-
If a request includes invalid query parameters, the service returns a `Warnings`
182+
Synthesizes text to audio that is spoken in the specified voice. The service bases
183+
its understanding of the language for the input text on the specified voice. Use a
184+
voice that matches the language of the input text.
185+
The service returns the synthesized audio stream as an array of bytes. You can
186+
pass a maximum of 5 KB of text to the service.
187+
**See also:** [Synthesizing text to
188+
audio](/docs/services/text-to-speech/http.html#synthesize).
189+
### Audio formats (accept types)
190+
The service can return audio in the following formats (MIME types).
191+
* Where indicated, you can optionally specify the sampling rate (`rate`) of the
192+
audio. You must specify a sampling rate for the `audio/l16` and `audio/mulaw`
193+
formats. A specified sampling rate must lie in the range of 8 kHz to 192 kHz.
194+
* For the `audio/l16` format, you can optionally specify the endianness
195+
(`endianness`) of the audio: `endianness=big-endian` or
196+
`endianness=little-endian`.
197+
Use the `Accept` header or the `accept` parameter to specify the requested format
198+
of the response audio. If you omit an audio format altogether, the service returns
199+
the audio in Ogg format with the Opus codec (`audio/ogg;codecs=opus`). The service
200+
always returns single-channel audio.
201+
* `audio/basic`
202+
The service returns audio with a sampling rate of 8000 Hz.
203+
* `audio/flac`
204+
You can optionally specify the `rate` of the audio. The default sampling rate is
205+
22,050 Hz.
206+
* `audio/l16`
207+
You must specify the `rate` of the audio. You can optionally specify the
208+
`endianness` of the audio. The default endianness is `little-endian`.
209+
* `audio/mp3`
210+
You can optionally specify the `rate` of the audio. The default sampling rate is
211+
22,050 Hz.
212+
* `audio/mpeg`
213+
You can optionally specify the `rate` of the audio. The default sampling rate is
214+
22,050 Hz.
215+
* `audio/mulaw`
216+
You must specify the `rate` of the audio.
217+
* `audio/ogg`
218+
The service returns the audio in the `vorbis` codec. You can optionally specify
219+
the `rate` of the audio. The default sampling rate is 22,050 Hz.
220+
* `audio/ogg;codecs=opus`
221+
You can optionally specify the `rate` of the audio. The default sampling rate is
222+
22,050 Hz.
223+
* `audio/ogg;codecs=vorbis`
224+
You can optionally specify the `rate` of the audio. The default sampling rate is
225+
22,050 Hz.
226+
* `audio/wav`
227+
You can optionally specify the `rate` of the audio. The default sampling rate is
228+
22,050 Hz.
229+
* `audio/webm`
230+
The service returns the audio in the `opus` codec. The service returns audio
231+
with a sampling rate of 48,000 Hz.
232+
* `audio/webm;codecs=opus`
233+
The service returns audio with a sampling rate of 48,000 Hz.
234+
* `audio/webm;codecs=vorbis`
235+
You can optionally specify the `rate` of the audio. The default sampling rate is
236+
22,050 Hz.
237+
For more information about specifying an audio format, including additional
238+
details about some of the formats, see [Specifying an audio
239+
format](/docs/services/text-to-speech/http.html#format).
240+
### Warning messages
241+
If a request includes invalid query parameters, the service returns a `Warnings`
187242
response header that provides messages about the invalid parameters. The warning
188243
includes a descriptive message and a list of invalid argument strings. For
189244
example, a message such as `\"Unknown arguments:\"` or `\"Unknown url query
190-
arguments:\"` followed by a list of the form `\"invalid_arg_1, invalid_arg_2.\"`
191-
The request succeeds despite the warnings.
192-
**See also:** [Synthesizing text to
193-
audio](https://console.bluemix.net/docs/services/text-to-speech/http.html#synthesize).
245+
arguments:\"` followed by a list of the form `\"{invalid_arg_1},
246+
{invalid_arg_2}.\"` The request succeeds despite the warnings.
194247
195248
:param str text: The text to synthesize.
196-
:param str accept: The requested audio format (MIME type) of the audio. You can
197-
use the `Accept` header or the `accept` query parameter to specify the audio
198-
format. (For the `audio/l16` format, you can optionally specify
199-
`endianness=big-endian` or `endianness=little-endian`; the default is little
200-
endian.) For detailed information about the supported audio formats and sampling
201-
rates, see [Specifying an audio
202-
format](https://console.bluemix.net/docs/services/text-to-speech/http.html#format).
249+
:param str accept: The requested format (MIME type) of the audio. You can use the
250+
`Accept` header or the `accept` parameter to specify the audio format. For more
251+
information about specifying an audio format, see **Audio formats (accept types)**
252+
in the method description.
253+
Default: `audio/ogg;codecs=opus`.
203254
:param str voice: The voice to use for synthesis.
204255
:param str customization_id: The customization ID (GUID) of a custom voice model
205256
to use for the synthesis. If a custom voice model is specified, it is guaranteed
@@ -252,7 +303,7 @@ def get_pronunciation(self,
252303
for a specific custom voice model to see the translation for that voice model.
253304
**Note:** This method is currently a beta release.
254305
**See also:** [Querying a word from a
255-
language](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordsQueryLanguage).
306+
language](/docs/services/text-to-speech/custom-entries.html#cuWordsQueryLanguage).
256307
257308
:param str text: The word for which the pronunciation is requested.
258309
:param str voice: A voice that specifies the language in which the pronunciation
@@ -313,7 +364,7 @@ def create_voice_model(self,
313364
used to create it.
314365
**Note:** This method is currently a beta release.
315366
**See also:** [Creating a custom
316-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-models.html#cuModelsCreate).
367+
model](/docs/services/text-to-speech/custom-models.html#cuModelsCreate).
317368
318369
:param str name: The name of the new custom voice model.
319370
:param str language: The language of the new custom voice model. Omit the
@@ -351,7 +402,7 @@ def delete_voice_model(self, customization_id, **kwargs):
351402
instance of the service that owns a model to delete it.
352403
**Note:** This method is currently a beta release.
353404
**See also:** [Deleting a custom
354-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-models.html#cuModelsDelete).
405+
model](/docs/services/text-to-speech/custom-models.html#cuModelsDelete).
355406
356407
:param str customization_id: The customization ID (GUID) of the custom voice
357408
model. You must make the request with service credentials created for the instance
@@ -384,7 +435,7 @@ def get_voice_model(self, customization_id, **kwargs):
384435
voice model, use the **List custom models** method.
385436
**Note:** This method is currently a beta release.
386437
**See also:** [Querying a custom
387-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-models.html#cuModelsQuery).
438+
model](/docs/services/text-to-speech/custom-models.html#cuModelsQuery).
388439
389440
:param str customization_id: The customization ID (GUID) of the custom voice
390441
model. You must make the request with service credentials created for the instance
@@ -419,7 +470,7 @@ def list_voice_models(self, language=None, **kwargs):
419470
about it.
420471
**Note:** This method is currently a beta release.
421472
**See also:** [Querying all custom
422-
models](https://console.bluemix.net/docs/services/text-to-speech/custom-models.html#cuModelsQueryAll).
473+
models](/docs/services/text-to-speech/custom-models.html#cuModelsQueryAll).
423474
424475
:param str language: The language for which custom voice models that are owned by
425476
the requesting service credentials are to be returned. Omit the parameter to see
@@ -472,11 +523,10 @@ def update_voice_model(self,
472523
**Note:** This method is currently a beta release.
473524
**See also:**
474525
* [Updating a custom
475-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-models.html#cuModelsUpdate)
526+
model](/docs/services/text-to-speech/custom-models.html#cuModelsUpdate)
476527
* [Adding words to a Japanese custom
477-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
478-
* [Understanding
479-
customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
528+
model](/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
529+
* [Understanding customization](/docs/services/text-to-speech/custom-intro.html).
480530
481531
:param str customization_id: The customization ID (GUID) of the custom voice
482532
model. You must make the request with service credentials created for the instance
@@ -543,11 +593,10 @@ def add_word(self,
543593
**Note:** This method is currently a beta release.
544594
**See also:**
545595
* [Adding a single word to a custom
546-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordAdd)
596+
model](/docs/services/text-to-speech/custom-entries.html#cuWordAdd)
547597
* [Adding words to a Japanese custom
548-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
549-
* [Understanding
550-
customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
598+
model](/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
599+
* [Understanding customization](/docs/services/text-to-speech/custom-intro.html).
551600
552601
:param str customization_id: The customization ID (GUID) of the custom voice
553602
model. You must make the request with service credentials created for the instance
@@ -563,7 +612,7 @@ def add_word(self,
563612
create only a single entry, with or without a single part of speech, for any word;
564613
you cannot create multiple entries with different parts of speech for the same
565614
word. For more information, see [Working with Japanese
566-
entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
615+
entries](/docs/services/text-to-speech/custom-rules.html#jaNotes).
567616
:param dict headers: A `dict` containing the request headers
568617
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
569618
:rtype: DetailedResponse
@@ -610,11 +659,10 @@ def add_words(self, customization_id, words, **kwargs):
610659
**Note:** This method is currently a beta release.
611660
**See also:**
612661
* [Adding multiple words to a custom
613-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordsAdd)
662+
model](/docs/services/text-to-speech/custom-entries.html#cuWordsAdd)
614663
* [Adding words to a Japanese custom
615-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
616-
* [Understanding
617-
customization](https://console.bluemix.net/docs/services/text-to-speech/custom-intro.html).
664+
model](/docs/services/text-to-speech/custom-entries.html#cuJapaneseAdd)
665+
* [Understanding customization](/docs/services/text-to-speech/custom-intro.html).
618666
619667
:param str customization_id: The customization ID (GUID) of the custom voice
620668
model. You must make the request with service credentials created for the instance
@@ -661,7 +709,7 @@ def delete_word(self, customization_id, word, **kwargs):
661709
credentials for the instance of the service that owns a model to delete its words.
662710
**Note:** This method is currently a beta release.
663711
**See also:** [Deleting a word from a custom
664-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordDelete).
712+
model](/docs/services/text-to-speech/custom-entries.html#cuWordDelete).
665713
666714
:param str customization_id: The customization ID (GUID) of the custom voice
667715
model. You must make the request with service credentials created for the instance
@@ -696,7 +744,7 @@ def get_word(self, customization_id, word, **kwargs):
696744
the instance of the service that owns a model to list its words.
697745
**Note:** This method is currently a beta release.
698746
**See also:** [Querying a single word from a custom
699-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordQueryModel).
747+
model](/docs/services/text-to-speech/custom-entries.html#cuWordQueryModel).
700748
701749
:param str customization_id: The customization ID (GUID) of the custom voice
702750
model. You must make the request with service credentials created for the instance
@@ -732,7 +780,7 @@ def list_words(self, customization_id, **kwargs):
732780
words.
733781
**Note:** This method is currently a beta release.
734782
**See also:** [Querying all words from a custom
735-
model](https://console.bluemix.net/docs/services/text-to-speech/custom-entries.html#cuWordsQueryModel).
783+
model](/docs/services/text-to-speech/custom-entries.html#cuWordsQueryModel).
736784
737785
:param str customization_id: The customization ID (GUID) of the custom voice
738786
model. You must make the request with service credentials created for the instance
@@ -771,7 +819,7 @@ def delete_user_data(self, customer_id, **kwargs):
771819
You associate a customer ID with data by passing the `X-Watson-Metadata` header
772820
with a request that passes the data.
773821
**See also:** [Information
774-
security](https://console.bluemix.net/docs/services/text-to-speech/information-security.html).
822+
security](/docs/services/text-to-speech/information-security.html).
775823
776824
:param str customer_id: The customer ID for which all data is to be deleted.
777825
:param dict headers: A `dict` containing the request headers
@@ -858,7 +906,7 @@ def __ne__(self, other):
858906

859907
class SupportedFeatures(object):
860908
"""
861-
SupportedFeatures.
909+
Describes the additional service features that are supported with the voice.
862910
863911
:attr bool custom_pronunciation: If `true`, the voice can be customized; if `false`,
864912
the voice cannot be customized. (Same as `customizable`.).
@@ -937,7 +985,7 @@ class Translation(object):
937985
can create only a single entry, with or without a single part of speech, for any word;
938986
you cannot create multiple entries with different parts of speech for the same word.
939987
For more information, see [Working with Japanese
940-
entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
988+
entries](/docs/services/text-to-speech/custom-rules.html#jaNotes).
941989
"""
942990

943991
def __init__(self, translation, part_of_speech=None):
@@ -953,7 +1001,7 @@ def __init__(self, translation, part_of_speech=None):
9531001
word. You can create only a single entry, with or without a single part of speech,
9541002
for any word; you cannot create multiple entries with different parts of speech
9551003
for the same word. For more information, see [Working with Japanese
956-
entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
1004+
entries](/docs/services/text-to-speech/custom-rules.html#jaNotes).
9571005
"""
9581006
self.translation = translation
9591007
self.part_of_speech = part_of_speech
@@ -1010,7 +1058,7 @@ class Voice(object):
10101058
cannot be customized. (Same as `custom_pronunciation`; maintained for backward
10111059
compatibility.).
10121060
:attr SupportedFeatures supported_features: Describes the additional service features
1013-
supported with the voice.
1061+
that are supported with the voice.
10141062
:attr VoiceModel customization: (optional) Returns information about a specified
10151063
custom voice model. This field is returned only by the **Get a voice** method and only
10161064
when you specify the customization ID of a custom voice model.
@@ -1038,7 +1086,7 @@ def __init__(self,
10381086
voice cannot be customized. (Same as `custom_pronunciation`; maintained for
10391087
backward compatibility.).
10401088
:param SupportedFeatures supported_features: Describes the additional service
1041-
features supported with the voice.
1089+
features that are supported with the voice.
10421090
:param VoiceModel customization: (optional) Returns information about a specified
10431091
custom voice model. This field is returned only by the **Get a voice** method and
10441092
only when you specify the customization ID of a custom voice model.
@@ -1393,7 +1441,7 @@ class Word(object):
13931441
can create only a single entry, with or without a single part of speech, for any word;
13941442
you cannot create multiple entries with different parts of speech for the same word.
13951443
For more information, see [Working with Japanese
1396-
entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
1444+
entries](/docs/services/text-to-speech/custom-rules.html#jaNotes).
13971445
"""
13981446

13991447
def __init__(self, word, translation, part_of_speech=None):
@@ -1411,7 +1459,7 @@ def __init__(self, word, translation, part_of_speech=None):
14111459
word. You can create only a single entry, with or without a single part of speech,
14121460
for any word; you cannot create multiple entries with different parts of speech
14131461
for the same word. For more information, see [Working with Japanese
1414-
entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
1462+
entries](/docs/services/text-to-speech/custom-rules.html#jaNotes).
14151463
"""
14161464
self.word = word
14171465
self.translation = translation

0 commit comments

Comments
 (0)