Skip to content

Commit f52c4cd

Browse files
committed
update readme
1 parent 5d7ceea commit f52c4cd

File tree

1 file changed

+151
-80
lines changed
  • src/IBM.WatsonDeveloperCloud.SpeechToText

1 file changed

+151
-80
lines changed

src/IBM.WatsonDeveloperCloud.SpeechToText/README.md

Lines changed: 151 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,42 @@ Retrieves information about a single specified model that is available for use w
6060
var results = _speechToText.GetModel("<model-name>");
6161
```
6262

63-
#### Recognize audio via websockets
64-
Sends audio and returns transcription results for recognition requests over a WebSocket connection. Requests and responses are enabled over a single TCP connection that abstracts much of the complexity of the request to offer efficient implementation, low latency, high throughput, and an asynchronous response. By default, only final results are returned for any request; to enable interim results, set the interim_results parameter to true.
63+
#### Recognize audio
64+
###### Streaming mode
65+
66+
For requests to transcribe live audio as it becomes available or to transcribe multiple audio files with multipart requests, you must set the Transfer-Encoding header to chunked to use streaming mode. In streaming mode, the server closes the connection (status code 408) if the service receives no data chunk for 30 seconds and the service has no audio to transcribe for 30 seconds. The server also closes the connection (status code 400) if no speech is detected for inactivity_timeout seconds of audio (not processing time); use the inactivity_timeout parameter to change the default of 30 seconds.
67+
68+
###### Non-multipart requests
69+
For non-multipart requests, you specify all parameters of the request as a collection of request headers and query parameters, and you provide the audio as the body of the request. This is the recommended means of submitting a recognition request. Use the following parameters:
70+
71+
* Required: Content-Type and body
72+
* Optional: Transfer-Encoding, model, customization_id, continuous, inactivity_timeout, keywords, keywords_threshold, max_alternatives, word_alternatives_threshold, word_confidence, timestamps, profanity_filter, smart_formatting, and speaker_labels
73+
74+
###### Multipart requests
75+
76+
For multipart requests, you specify a few parameters of the request as request headers and query parameters, but you specify most parameters as multipart form data in the form of JSON metadata, in which only part_content_type is required. You then specify the audio files for the request as subsequent parts of the form data. Use this approach with browsers that do not support JavaScript or when the parameters of the request are greater than the 8 KB limit imposed by most HTTP servers and proxies. Use the following parameters:
77+
78+
* Required: Content-Type, metadata, and upload
79+
* Optional: Transfer-Encoding, model, and customization_id
80+
81+
An example of the multipart metadata for a pair of FLAC files follows. This first part of the request is sent as JSON; the remaining parts are the audio files for the request.
6582

66-
The service imposes a data size limit of 100 MB per connection. It automatically detects the endianness of the incoming audio and, for audio that includes multiple channels, downmixes the audio to one-channel mono during transcoding.
67-
```cs
6883
```
84+
metadata="{\"part_content_type\":\"audio/flac\",\"data_parts_count\":2,\"continuous\":true,\"inactivity_timeout\"=-1}"
85+
```
86+
87+
Note about the Try It Out feature: The Try it out! button is not supported for use with the the POST /v1/recognize method. For examples of calls to the method, see the [Speech to Text API reference][speech-to-text].
6988

70-
#### Recognize audio via file
71-
Sends audio and returns transcription results for a sessionless recognition request. Returns only the final results.
7289
```cs
7390
// open and read an audio file
7491
using (FileStream fs = File.OpenRead("<path-to-audio-file>"))
7592
{
76-
// get a transcript of the audio file
93+
// get a transcript of the audio file.
7794
var results = _speechToText.Recognize(fs);
7895
}
79-
```
8096

81-
<!-- #### Recognize audio via files
82-
Sends audio and returns transcription results for a sessionless recognition request submitted as multipart form data. Returns only the final results.
83-
```cs
84-
``` -->
97+
98+
```
8599

86100
#### Create a session
87101
Creates a session and locks recognition requests to that engine. You can use the session for multiple recognition requests so that each request is processed with the same engine. The session expires after 30 seconds of inactivity. Use the Get status method to prevent the session from expiring.
@@ -97,20 +111,46 @@ Checks whether a specified session can accept another recognition request. Concu
97111
var recognizeStatus = _speechToText.GetSessionStatus("<session-id>");
98112
```
99113

100-
<!-- #### Observe session result
114+
#### Observe session result
101115
Requests results for a recognition task within a specified session. You can submit this method multiple times for the same recognition task. To see interim results, set the interim_results parameter to true. The request must pass the cookie that was returned by the Create a session method.
102116
```cs
103-
``` -->
117+
// set up observe
118+
var taskObserveResult = Task.Factory.StartNew<List<SpeechRecognitionEvent>>(() =>
119+
{
120+
return service.ObserveResult(<session-id>);
121+
});
104122

105-
<!-- #### Recognize session audio
123+
// get results
124+
taskObserveResult.ContinueWith((antecedent) =>
125+
{
126+
var results = antecedent.Result;
127+
});
128+
129+
// recognize session audio
130+
var taskRecognizeWithSession = Task.Factory.StartNew(() =>
131+
{
132+
service.RecognizeWithSession(<session-id>, <audio-stream>.GetMediaTypeFromFile(), <metadata>, <audio-stream>, "chunked", <model-name>);
133+
});
134+
```
135+
136+
#### Recognize session audio
106137
Sends audio and returns transcription results for a session-based recognition request. By default, returns only the final transcription results for the request. To see interim results, set the parameter interim_results to true in a call to the Observe result method.
107138
```cs
108-
``` -->
139+
// recognize session audio
140+
var taskRecognizeWithSession = Task.Factory.StartNew(() =>
141+
{
142+
service.RecognizeWithSession(<session-id>, <audio-stream>.GetMediaTypeFromFile(), <metadata>, <audio-stream>, "chunked", <model-name>);
143+
});
144+
```
109145

110-
<!-- #### Recognize multipart session audio
146+
#### Recognize multipart session audio
111147
Sends audio and returns transcription results for a session-based recognition request submitted as multipart form data. By default, returns only the final transcription results for the request.
112148
```cs
113-
``` -->
149+
using (FileStream fs = File.OpenRead("<path-to-audio-file>"))
150+
{
151+
var speechEvent = _speechToText.RecognizeWithSession(<session-id>, fs.GetMediaTypeFromFile(), fs);
152+
}
153+
```
114154

115155
#### Delete a session
116156
Deletes an existing session and its engine. The request must pass the cookie that was returned by the Create a session method. You cannot send requests to a session after it is deleted. By default, a session expires after 30 seconds of inactivity if you do not delete it first.
@@ -119,118 +159,149 @@ Deletes an existing session and its engine. The request must pass the cookie tha
119159
_speechToText.DeleteSession("<session-id>");
120160
```
121161

122-
<!-- #### Register a callback
123-
Registers a callback URL with the service for use with subsequent asynchronous recognition requests. The service attempts to register, or white-list, the callback URL if it is not already registered by sending a GET request to the callback URL. The service passes a random alphanumeric challenge string via the challenge_string query parameter of the request.
124-
```cs
125-
``` -->
126-
127-
<!-- #### Create a job
128-
Creates a job for a new asynchronous recognition request. The job is owned by the user whose service credentials are used to create it. How you learn the status and results of a job depends on the parameters you include with the job creation request:
129-
130-
* By callback notification: Include the callback_url query parameter to specify a URL to which the service is to send callback notifications when the status of the job changes. Optionally, you can also include the events and user_token query parameters to subscribe to specific events and to specify a string that is to be included with each notification for the job.
131-
132-
* By polling the service: Omit the callback_url, events, and user_token query parameters. You must then use the Check jobs or Check a job method to check the status of the job, using the latter to retrieve the results when the job is complete.
133-
134-
```cs
135-
``` -->
136-
137-
<!-- #### Check jobs
138-
Returns the status and ID of all outstanding jobs associated with the service credentials with which it is called. The method also returns the creation and update times of each job, and, if a job was created with a callback URL and a user token, the user token for the job. To obtain the results for a job whose status is completed, use the Check a job method. A job and its results remain available until you delete them with the Delete a job method or until the job's time to live expires, whichever comes first.
139-
```cs
140-
``` -->
141-
142-
<!-- #### Check a job
143-
Returns information about a specified job. The response always includes the status of the job and its creation and update times. If the status is completed, the response also includes the results of the recognition request. You must submit the request with the service credentials of the user who created the job.
144-
```cs
145-
``` -->
146-
147-
<!-- #### Delete a job
148-
Deletes the specified job. You cannot delete a job that the service is actively processing. Once you delete a job, its results are no longer available. The service automatically deletes a job and its results when the time to live for the results expires. You must submit the request with the service credentials of the user who created the job.
149-
```cs
150-
``` -->
151-
152-
<!-- #### Create a custom model
162+
#### Create a custom model
153163
Creates a new custom language model for a specified base language model. The custom language model can be used only with the base language model for which it is created. The new model is owned by the individual whose service credentials are used to create it.
154164
```cs
155-
``` -->
165+
var result = _speechToText.CreateCustomModel(<custom-model-name>, <base-model>, <custom-model-description>);
166+
```
156167

157-
<!-- #### List custom models
168+
#### List custom models
158169
Lists information about all custom language models that are owned by the calling user. Use the language query parameter to see all custom models for the specified language; omit the parameter to see all custom models for all languages.
159170
```cs
160-
``` -->
171+
var result = _speechToText.ListCustomModels();
172+
```
161173

162-
<!-- #### List a custom model
174+
#### List a custom model
163175
Lists information about a custom language model. Only the owner of a custom model can use this method to query information about the model.
164176
```cs
165-
``` -->
177+
var result = _speechToText.ListCustomModel("<customization-id>");
178+
```
166179

167-
<!-- #### Train a custom model
180+
#### Train a custom model
168181
Initiates the training of a custom language model with new corpora, words, or both. After adding training data to the custom model with the corpora or words methods, use this method to begin the actual training of the model on the new data. You can specify whether the custom model is to be trained with all words from its words resources or only with words that were added or modified by the user. Only the owner of a custom model can use this method to train the model.
169182
```cs
170-
``` -->
183+
var result = _speechToText.TrainCustomModel(_createdCustomizationID);
184+
```
171185

172-
<!-- #### Reset a custom model
186+
#### Reset a custom model
173187
Resets a custom language model by removing all corpora and words from the model. Resetting a custom model initializes the model to its state when it was first created. Metadata such as the name and language of the model are preserved. Only the owner of a custom model can use this method to reset the model.
174188
```cs
175-
``` -->
189+
var result = _speechToText.ResetCustomModel("<customization-id>");
190+
```
176191

177-
<!-- #### Upgrade a custom model
192+
#### Upgrade a custom model
178193
Upgrades a custom language model to the latest release level of the Speech to Text service. The method bases the upgrade on the latest trained data stored for the custom model. If the corpora or words for the model have changed since the model was last trained, you must use the Train a custom model method to train the model on the new data. Only the owner of a custom model can use this method to upgrade the model.
179194

180195
Note: This method is not currently implemented. It will be added for a future release of the API.
181196
```cs
182-
``` -->
197+
var result = _speechToText.UpgradeCustomModel("<customization-id>");
198+
```
183199

184-
<!-- #### Delete a custom model
200+
#### Delete a custom model
185201
Deletes an existing custom language model. The custom model cannot be deleted if another request, such as adding a corpus to the model, is currently being processed. Only the owner of a custom model can use this method to delete the model.
186202
```cs
187-
``` -->
203+
var result = _speechToText.DeleteCustomModel("<customization-id>");
204+
```
188205

189-
<!-- #### Add a corpus
206+
#### Add a corpus
190207
Adds a single corpus text file of new training data to the custom language model. Use multiple requests to submit multiple corpus text files. Only the owner of a custom model can use this method to add a corpus to the model. Note that adding a corpus does not affect the custom model until you train the model for the new data by using the Train a custom model method.
191208
```cs
192-
``` -->
209+
using (FileStream fs = File.OpenRead("<path-to-corpus-file>"))
210+
{
211+
object result = _speechToText.AddCorpus("<customization_id>", "<corpus-name>", "<allow-overwrite>", fs);
212+
}
213+
```
193214

194-
<!-- #### List corpora
215+
#### List corpora
195216
Lists information about all corpora that have been added to the specified custom language model. The information includes the total number of words and out-of-vocabulary (OOV) words, name, and status of each corpus. Only the owner of a custom model can use this method to list the model's corpora.
196217
```cs
197-
``` -->
218+
var result = _speechToText.ListCorpora("<customization-id>");
219+
```
198220

199-
<!-- #### List a corpus
221+
#### List a corpus
200222
Lists information about a single specified corpus. The information includes the total number of words and out-of-vocabulary (OOV) words, name, and status of the corpus. Only the owner of a custom model can use this method to list information about a corpus from the model.
201223
```cs
202-
``` -->
224+
var result = _speechToText.GetCorpus("<customization-id>", "<corpus-name>");
225+
```
203226

204-
<!-- #### Delete a corpus
227+
#### Delete a corpus
205228
Deletes an existing corpus from a custom language model. The service removes any out-of-vocabulary (OOV) words associated with the corpus from the custom model's words resource unless they were also added by another corpus or they have been modified in some way with the Add custom words or Add a custom word method. Removing a corpus does not affect the custom model until you train the model with the Train a custom model method. Only the owner of a custom model can use this method to delete a corpus from the model.
206229
```cs
207-
``` -->
230+
var result = _speechToText.DeleteCorpus("<customization-id>", "<corpus-name>");
231+
```
208232

209-
<!-- #### Add custom words
233+
#### Add custom words
210234
Adds one or more custom words to a custom language model. The service populates the words resource for a custom model with out-of-vocabulary (OOV) words found in each corpus added to the model. You can use this method to add additional words or to modify existing words in the words resource. Only the owner of a custom model can use this method to add or modify custom words associated with the model. Adding or modifying custom words does not affect the custom model until you train the model for the new data by using the Train a custom model method.
211235
```cs
212-
``` -->
236+
object result = _speechToText.AddCustomWords("<customization-id>",
237+
new Words()
238+
{
239+
WordsProperty = new List<Word>()
240+
{
241+
new Word()
242+
{
243+
DisplayAs = "Watson",
244+
SoundsLike = new List<string>()
245+
{
246+
"wat son"
247+
},
248+
WordProperty = "watson"
249+
},
250+
new Word()
251+
{
252+
DisplayAs = "C#",
253+
SoundsLike = new List<string>()
254+
{
255+
"si sharp"
256+
},
257+
WordProperty = "csharp"
258+
},
259+
new Word()
260+
{
261+
DisplayAs = "SDK",
262+
SoundsLike = new List<string>()
263+
{
264+
"S.D.K."
265+
},
266+
WordProperty = "sdk"
267+
}
268+
}
269+
});
270+
```
213271

214-
<!-- #### Add a custom word
272+
#### Add a custom word
215273
Adds a custom word to a custom language model. The service populates the words resource for a custom model with out-of-vocabulary (OOV) words found in each corpus added to the model. You can use this method to add additional words or to modify existing words in the words resource. Only the owner of a custom model can use this method to add or modify a custom word for the model. Adding or modifying a custom word does not affect the custom model until you train the model for the new data by using the Train a custom model method.
216274
```cs
217-
``` -->
275+
object result = _speechToText.AddCustomWord("<customization-id>",
276+
"<word-name>",
277+
new WordDefinition()
278+
{
279+
DisplayAs = "Social",
280+
SoundsLike = new List<string>()
281+
{
282+
"so cial"
283+
}
284+
});
285+
```
218286

219-
<!-- #### List custom words
287+
#### List custom words
220288
Lists information about all custom words from a custom language model. You can list all words from the custom model's words resource, only custom words that were added or modified by the user, or only OOV words that were extracted from corpora. Only the owner of a custom model can use this method to query the words from the model.
221289
```cs
222-
``` -->
290+
var result = _speechToText.ListCustomWords("<customization-id>");
291+
```
223292

224-
<!-- #### List a custom word
293+
#### List a custom word
225294
Lists information about a custom word from a custom language model. Only the owner of a custom model can use this method to query a word from the model.
226295
```cs
227-
``` -->
296+
var result = _speechToText.ListCustomWord("<customization-id>", "<word-name>");
297+
```
228298

229-
<!-- #### Delete a custom word
299+
#### Delete a custom word
230300
Deletes a custom word from a custom language model. You can remove any word that you added to the custom model's words resource via any means. However, if the word also exists in the service's base vocabulary, the service removes only the custom pronunciation for the word; the word remains in the base vocabulary.
231301

232302
Removing a custom word does not affect the custom model until you train the model with the Train a custom model method. Only the owner of a custom model can use this method to delete a word from the model.
233303
```cs
234-
``` -->
304+
object result = _speechToText.DeleteCustomWord("<customization-id>", "<word-name>");
305+
```
235306

236307
[speech-to-text]: http://www.ibm.com/watson/developercloud/doc/speech-to-text/

0 commit comments

Comments
 (0)