Skip to content

Commit 179dfe9

Browse files
Merge pull request #392 from watson-developer-cloud/codegen/text-to-speech
Regenerate text to speech
2 parents 26c7b95 + 84ee57a commit 179dfe9

2 files changed

Lines changed: 21 additions & 80 deletions

File tree

test/unit/test_text_to_speech_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_custom_words():
220220

221221
text_to_speech.list_words(customization_id="custid")
222222
text_to_speech.add_words(
223-
customization_id="custid", words=["one", "two", "three"])
223+
customization_id="custid", words=[{"word": "one", "translation": "one"}, {"word": "two", "translation": "two"}])
224224
text_to_speech.get_word(customization_id="custid", word="word")
225225
text_to_speech.add_word(
226226
customization_id='custid', word="word", translation="I'm translated")

watson_developer_cloud/text_to_speech_v1.py

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self, url=default_url, username=None, password=None):
6565
use_vcap_services=True)
6666

6767
#########################
68-
# voices
68+
# Voices
6969
#########################
7070

7171
def get_voice(self, voice, customization_id=None):
@@ -113,7 +113,7 @@ def synthesize(self,
113113
Streaming speech synthesis of the text in the body parameter. Synthesizes text to spoken audio, returning the synthesized audio stream as an array of bytes.
114114
115115
:param str text: The text to synthesize.
116-
:param str accept: The requested audio format (MIME type) of the audio. You can use this header or the `accept` query parameter to specify the audio format. (For the `audio/l16` format, you can optionally specify `endianness=big-endian` or `endianness=little-endian`; the default is little endian.).
116+
:param str accept: The type of the response: audio/basic, audio/flac, audio/l16;rate=nnnn, audio/ogg, audio/ogg;codecs=opus, audio/ogg;codecs=vorbis, audio/mp3, audio/mpeg, audio/mulaw;rate=nnnn, audio/wav, audio/webm, audio/webm;codecs=opus, or audio/webm;codecs=vorbis.
117117
:param str voice: The voice to use for synthesis. Retrieve available voices with the `GET /v1/voices` method.
118118
:param str customization_id: The GUID of a custom voice model to use for the synthesis. If a custom voice model is specified, it is guaranteed to work only if it matches the language of the indicated voice. You must make the request with service credentials created for the instance of the service that owns the custom model. Omit the parameter to use the specified voice with no customization.
119119
:return: A `Response <Response>` object representing the response.
@@ -139,7 +139,7 @@ def synthesize(self,
139139
return response
140140

141141
#########################
142-
# pronunciation
142+
# Pronunciation
143143
#########################
144144

145145
def get_pronunciation(self,
@@ -181,7 +181,7 @@ def pronunciation(self, text, voice=None, pronunciation_format='ipa'):
181181
return self.get_pronunciation(text, voice, pronunciation_format)
182182

183183
#########################
184-
# customVoiceModels
184+
# Custom voice models
185185
#########################
186186

187187
def create_voice_model(self, name, language=None, description=None):
@@ -239,7 +239,10 @@ def get_voice_model(self, customization_id):
239239
Lists all information about the custom voice model with the specified
240240
`customization_id`. In addition to metadata such as the name and description of
241241
the voice model, the output includes the words in the model and their translations
242-
as defined in the model. **Note:** This method is currently a beta release.
242+
as defined in the model. To see just the metadata for a voice model, use the `GET
243+
/v1/customizations` method. You must use credentials for the instance of the
244+
service that owns a model to list information about it. **Note:** This method is
245+
currently a beta release.
243246
244247
:param str customization_id: The GUID of the custom voice model that is to be queried. You must make the request with service credentials created for the instance of the service that owns the custom model.
245248
:return: A `dict` containing the `VoiceModel` response.
@@ -258,8 +261,13 @@ def get_customization(self, customization_id):
258261

259262
def list_voice_models(self, language=None):
260263
"""
261-
Lists all available custom voice models for a language or for all languages.
262-
**Note:** This method is currently a beta release.
264+
Lists metadata such as the name and description for the custom voice models that
265+
you own. Use the `language` query parameter to list the voice models that you own
266+
for the specified language only. Omit the parameter to see all voice models that
267+
you own for all languages. To see the words in addition to the metadata for a
268+
specific voice model, use the `GET /v1/customizations/{customization_id}` method.
269+
You must use credentials for the instance of the service that owns a model to list
270+
information about it. **Note:** This method is currently a beta release.
263271
264272
:param str language: The language for which custom voice models that are owned by the requesting service credentials are to be returned. Omit the parameter to see all custom voice models that are owned by the requester.
265273
:return: A `dict` containing the `VoiceModels` response.
@@ -295,13 +303,13 @@ def update_voice_model(self,
295303
:param str customization_id: The GUID of the custom voice model that is to be updated. You must make the request with service credentials created for the instance of the service that owns the custom model.
296304
:param str name: A new name for the custom voice model.
297305
:param str description: A new description for the custom voice model.
298-
:param list[CustomWord] words: An array of words and their translations that are to be added or updated for the custom voice model. Pass an empty array to make no additions or updates.
306+
:param list[Word] words: An array of words and their translations that are to be added or updated for the custom voice model. Pass an empty array to make no additions or updates.
299307
:rtype: None
300308
"""
301309
if customization_id is None:
302310
raise ValueError('customization_id must be provided')
303311
if words is not None:
304-
words = [self._convert_model(x) for x in words]
312+
words = [self._convert_model(x, Word) for x in words]
305313
data = {'name': name, 'description': description, 'words': words}
306314
url = '/v1/customizations/{0}'.format(
307315
*self._encode_path_vars(customization_id))
@@ -314,7 +322,7 @@ def update_customization(self, customization_id, name=None,
314322
return self.update_voice_model(customization_id, name, description, words)
315323

316324
#########################
317-
# customWords
325+
# Custom words
318326
#########################
319327

320328
def add_word(self, customization_id, word, translation,
@@ -363,14 +371,14 @@ def add_words(self, customization_id, words):
363371
method is currently a beta release.
364372
365373
:param str customization_id: The GUID of the custom voice model that is to be updated. You must make the request with service credentials created for the instance of the service that owns the custom model.
366-
:param list[CustomWord] words: An array of `CustomWord` objects that provides information about the words and their translations that are to be added or updated for the custom voice model.
374+
:param list[Word] words: An array of words and their translations from the custom voice model. The words are listed in alphabetical order, with uppercase letters listed before lowercase letters. The array is empty if the custom model contains no words.
367375
:rtype: None
368376
"""
369377
if customization_id is None:
370378
raise ValueError('customization_id must be provided')
371379
if words is None:
372380
raise ValueError('words must be provided')
373-
words = [self._convert_model(x) for x in words]
381+
words = [self._convert_model(x, Word) for x in words]
374382
data = {'words': words}
375383
url = '/v1/customizations/{0}/words'.format(
376384
*self._encode_path_vars(customization_id))
@@ -464,73 +472,6 @@ def get_customization_words(self, customization_id):
464472
# Models
465473
##############################################################################
466474

467-
468-
class CustomWord(object):
469-
"""
470-
CustomWord.
471-
472-
:attr str word: A word that is to be added or updated for the custom voice model.
473-
:attr str translation: The phonetic or sounds-like translation for the word. A phonetic translation is based on the SSML format for representing the phonetic string of a word either as an IPA or IBM SPR translation. A sounds-like translation consists of one or more words that, when combined, sound like the word.
474-
:attr str part_of_speech: (optional) **Japanese only.** The part of speech for the word. The service uses the value to produce the correct intonation for the word. You can create only a single entry, with or without a single part of speech, for any word; you cannot create multiple entries with different parts of speech for the same word. For more information, see [Working with Japanese entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
475-
"""
476-
477-
def __init__(self, word, translation, part_of_speech=None):
478-
"""
479-
Initialize a CustomWord object.
480-
481-
:param str word: A word that is to be added or updated for the custom voice model.
482-
:param str translation: The phonetic or sounds-like translation for the word. A phonetic translation is based on the SSML format for representing the phonetic string of a word either as an IPA or IBM SPR translation. A sounds-like translation consists of one or more words that, when combined, sound like the word.
483-
:param str part_of_speech: (optional) **Japanese only.** The part of speech for the word. The service uses the value to produce the correct intonation for the word. You can create only a single entry, with or without a single part of speech, for any word; you cannot create multiple entries with different parts of speech for the same word. For more information, see [Working with Japanese entries](https://console.bluemix.net/docs/services/text-to-speech/custom-rules.html#jaNotes).
484-
"""
485-
self.word = word
486-
self.translation = translation
487-
self.part_of_speech = part_of_speech
488-
489-
@classmethod
490-
def _from_dict(cls, _dict):
491-
"""Initialize a CustomWord object from a json dictionary."""
492-
args = {}
493-
if 'word' in _dict:
494-
args['word'] = _dict['word']
495-
else:
496-
raise ValueError(
497-
'Required property \'word\' not present in CustomWord JSON')
498-
if 'translation' in _dict:
499-
args['translation'] = _dict['translation']
500-
else:
501-
raise ValueError(
502-
'Required property \'translation\' not present in CustomWord JSON'
503-
)
504-
if 'part_of_speech' in _dict:
505-
args['part_of_speech'] = _dict['part_of_speech']
506-
return cls(**args)
507-
508-
def _to_dict(self):
509-
"""Return a json dictionary representing this model."""
510-
_dict = {}
511-
if hasattr(self, 'word') and self.word is not None:
512-
_dict['word'] = self.word
513-
if hasattr(self, 'translation') and self.translation is not None:
514-
_dict['translation'] = self.translation
515-
if hasattr(self, 'part_of_speech') and self.part_of_speech is not None:
516-
_dict['part_of_speech'] = self.part_of_speech
517-
return _dict
518-
519-
def __str__(self):
520-
"""Return a `str` version of this CustomWord object."""
521-
return json.dumps(self._to_dict(), indent=2)
522-
523-
def __eq__(self, other):
524-
"""Return `true` when self and other are equal, false otherwise."""
525-
if not isinstance(other, self.__class__):
526-
return False
527-
return self.__dict__ == other.__dict__
528-
529-
def __ne__(self, other):
530-
"""Return `true` when self and other are not equal, false otherwise."""
531-
return not self == other
532-
533-
534475
class Pronunciation(object):
535476
"""
536477
Pronunciation.

0 commit comments

Comments
 (0)