Skip to content

Commit 1c3d728

Browse files
committed
Regenerate speech to text
1 parent b705442 commit 1c3d728

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

test/unit/test_speech_to_text_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_recognitions():
119119
with open(
120120
os.path.join(os.path.dirname(__file__), '../../resources/speech.wav'),
121121
'rb') as audio_file:
122-
speech_to_text.create_job(audio=audio_file)
122+
speech_to_text.create_job(audio=audio_file, content_type='audio/basic')
123123
assert responses.calls[2].response.json() == {'status': 'waiting'}
124124

125125
speech_to_text.delete_job('jobid')

watson_developer_cloud/speech_to_text_v1.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self, url=default_url, username=None, password=None):
7272
use_vcap_services=True)
7373

7474
#########################
75-
# models
75+
# Models
7676
#########################
7777

7878
def get_model(self, model_id):
@@ -113,7 +113,7 @@ def models(self):
113113
return self.list_models
114114

115115
#########################
116-
# recognize
116+
# Sessionless
117117
#########################
118118

119119
def recognize(self,
@@ -123,7 +123,7 @@ def recognize(self,
123123
customization_weight=None,
124124
version=None,
125125
audio=None,
126-
content_type='audio/basic',
126+
content_type=None,
127127
inactivity_timeout=None,
128128
keywords=None,
129129
keywords_threshold=None,
@@ -277,7 +277,7 @@ def recognize_with_websocket(self,
277277
headers)
278278

279279
#########################
280-
# asynchronous
280+
# Asynchronous
281281
#########################
282282

283283
def check_job(self, id):
@@ -307,12 +307,13 @@ def check_jobs(self):
307307

308308
def create_job(self,
309309
audio,
310-
content_type='audio/basic',
310+
content_type,
311+
transfer_encoding=None,
312+
model=None,
311313
callback_url=None,
312314
events=None,
313315
user_token=None,
314316
results_ttl=None,
315-
model=None,
316317
customization_id=None,
317318
acoustic_customization_id=None,
318319
customization_weight=None,
@@ -332,11 +333,12 @@ def create_job(self,
332333
333334
:param str audio: Audio to transcribe in the format specified by the `Content-Type` header.
334335
:param str content_type: The type of the input: audio/basic, audio/flac, audio/l16, audio/mp3, audio/mpeg, audio/mulaw, audio/ogg, audio/ogg;codecs=opus, audio/ogg;codecs=vorbis, audio/wav, audio/webm, audio/webm;codecs=opus, or audio/webm;codecs=vorbis.
336+
:param str transfer_encoding: Set to `chunked` to send the audio in streaming mode. The data does not need to exist fully before being streamed to the service.
337+
:param str model: The identifier of the model to be used for the recognition request. (Use `GET /v1/models` for a list of available models.).
335338
:param str callback_url: A URL to which callback notifications are to be sent. The URL must already be successfully white-listed by using the `POST /v1/register_callback` method. Omit the parameter to poll the service for job completion and results. You can include the same callback URL with any number of job creation requests. Use the `user_token` query parameter to specify a unique user-specified string with each job to differentiate the callback notifications for the jobs.
336339
:param str events: If the job includes a callback URL, a comma-separated list of notification events to which to subscribe. Valid events are: `recognitions.started` generates a callback notification when the service begins to process the job. `recognitions.completed` generates a callback notification when the job is complete; you must use the `GET /v1/recognitions/{id}` method to retrieve the results before they time out or are deleted. `recognitions.completed_with_results` generates a callback notification when the job is complete; the notification includes the results of the request. `recognitions.failed` generates a callback notification if the service experiences an error while processing the job. Omit the parameter to subscribe to the default events: `recognitions.started`, `recognitions.completed`, and `recognitions.failed`. The `recognitions.completed` and `recognitions.completed_with_results` events are incompatible; you can specify only of the two events. If the job does not include a callback URL, omit the parameter.
337340
:param str user_token: If the job includes a callback URL, a user-specified string that the service is to include with each callback notification for the job; the token allows the user to maintain an internal mapping between jobs and notification events. If the job does not include a callback URL, omit the parameter.
338341
:param int results_ttl: The number of minutes for which the results are to be available after the job has finished. If not delivered via a callback, the results must be retrieved within this time. Omit the parameter to use a time to live of one week. The parameter is valid with or without a callback URL.
339-
:param str model: The identifier of the model to be used for the recognition request. (Use `GET /v1/models` for a list of available models.).
340342
:param str customization_id: The GUID of a custom language model that is to be used with the request. The base model of the specified custom language model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom language model is used.
341343
:param str acoustic_customization_id: The GUID of a custom acoustic model that is to be used with the request. The base model of the specified custom acoustic model must match the model specified with the `model` parameter. You must make the request with service credentials created for the instance of the service that owns the custom model. By default, no custom acoustic model is used.
342344
:param float customization_weight: If you specify a `customization_id` with the request, you can use the `customization_weight` parameter to tell the service how much weight to give to words from the custom language model compared to those from the base model for speech recognition. Specify a value between 0.0 and 1.0. Unless a different customization weight was specified for the custom model when it was trained, the default value is 0.3. A customization weight that you specify overrides a weight that was specified when the custom model was trained. The default value yields the best performance in general. Assign a higher value if your audio makes frequent use of OOV words from the custom model. Use caution when setting the weight: a higher value can improve the accuracy of phrases from the custom model's domain, but it can negatively affect performance on non-domain phrases.
@@ -358,13 +360,16 @@ def create_job(self,
358360
raise ValueError('audio must be provided')
359361
if content_type is None:
360362
raise ValueError('content_type must be provided')
361-
headers = {'Content-Type': content_type}
363+
headers = {
364+
'Content-Type': content_type,
365+
'Transfer-Encoding': transfer_encoding
366+
}
362367
params = {
368+
'model': model,
363369
'callback_url': callback_url,
364370
'events': events,
365371
'user_token': user_token,
366372
'results_ttl': results_ttl,
367-
'model': model,
368373
'customization_id': customization_id,
369374
'acoustic_customization_id': acoustic_customization_id,
370375
'customization_weight': customization_weight,
@@ -447,7 +452,7 @@ def unregister_callback(self, callback_url):
447452
return None
448453

449454
#########################
450-
# customLanguageModels
455+
# Custom language models
451456
#########################
452457

453458
def create_language_model(self,
@@ -631,7 +636,7 @@ def upgrade_language_model(self, customization_id):
631636
return None
632637

633638
#########################
634-
# customCorpora
639+
# Custom corpora
635640
#########################
636641

637642
def add_corpus(self,
@@ -734,7 +739,7 @@ def list_corpora(self, customization_id):
734739
return response
735740

736741
#########################
737-
# customWords
742+
# Custom words
738743
#########################
739744

740745
def add_word(self,
@@ -785,7 +790,7 @@ def add_words(self, customization_id, words):
785790
raise ValueError('customization_id must be provided')
786791
if words is None:
787792
raise ValueError('words must be provided')
788-
words = [self._convert_model(x) for x in words]
793+
words = [self._convert_model(x, CustomWord) for x in words]
789794
data = {'words': words}
790795
url = '/v1/customizations/{0}/words'.format(
791796
*self._encode_path_vars(customization_id))
@@ -1031,14 +1036,14 @@ def upgrade_acoustic_model(self,
10311036
return None
10321037

10331038
#########################
1034-
# customAudioResources
1039+
# Custom audio resources
10351040
#########################
10361041

10371042
def add_audio(self,
10381043
customization_id,
10391044
audio_name,
10401045
audio_resource,
1041-
content_type='application/zip',
1046+
content_type,
10421047
contained_content_type=None,
10431048
allow_overwrite=None):
10441049
"""
@@ -2382,6 +2387,8 @@ def _from_dict(cls, _dict):
23822387
raise ValueError(
23832388
'Required property \'confidence\' not present in SpeakerLabelsResult JSON'
23842389
)
2390+
if 'final_results' in _dict:
2391+
args['final_results'] = _dict['final_results']
23852392
if 'final' in _dict:
23862393
args['final_results'] = _dict['final']
23872394
else:
@@ -2696,6 +2703,8 @@ def __init__(self,
26962703
def _from_dict(cls, _dict):
26972704
"""Initialize a SpeechRecognitionResult object from a json dictionary."""
26982705
args = {}
2706+
if 'final_results' in _dict:
2707+
args['final_results'] = _dict['final_results']
26992708
if 'final' in _dict:
27002709
args['final_results'] = _dict['final']
27012710
else:

0 commit comments

Comments
 (0)