Https://data.aliyun.com/product/nls?spm=5176.doc30437.2.1.UPDABu
Below is the most commonly used word recognition service to give you an entry-level example that shows you how to quickly use the various services of Smart voice interaction.
1. Account and service request, get access key ID and access key secret two number plus authentication parameters. 2. The app_key of "one word recognition" service supported by the speech recognition service is the following table, and the App_key of "social domain" is nls-service.
a word to identify App_key |
Voice data Format |
result return mode |
Field |
Nls-service |
16kHz sampled 16bit audio stream |
Non-streaming |
Social Chat |
Nls-service-streaming |
16kHz sampled 16bit audio stream |
Flow type |
Social Chat |
Nls-service-tv |
16kHz sampled 16bit audio stream |
Non-streaming |
Home Entertainment |
Nls-service-shopping |
16kHz sampled 16bit audio stream |
Non-streaming |
E-commerce shopping area |
Nls-service-care |
16kHz sampled 16bit audio stream |
Non-streaming |
Intelligent Customer Service Field |
Note:
(1) "Supported results return mode" includes "non-streaming" and "streaming" two modes, "non-streaming" is simply the user complete sentence to return to the recognition results, "streaming" mode when the user is speaking and return the recognition results.
(2) "One sentence recognition" Support areas include: Social chat, home Entertainment, e-commerce shopping, smart customer service and so on. The user can select the corresponding domain App_key for the specific usage scene.
3. Download the Java SDK and demo to start speech recognition.
3.1 Running demo to test voice service
Download the corresponding download package to the Java SDK page of the "one word recognition" service, including the Java SDK and demo project.
Open the Asrdemo.java method in the Java Demo project, replace the App_key, access key ID, access key Secret with your own account information, and then directly Run->java application.
NlsRequest req = new NlsRequest();
req.setApp_key("app_key"); // 替换为选定的app_key
req.setAsr_sc("pcm"); // 这里为测试准备的语音文件是pcm语音文件。
req.authorize("Access Key ID", "Access Key Secret"); // 替换为在数加平台申请到的"Access Key ID"和 "Access Key Secret"
If the execution succeeds, the log message "" Result "" Hello Cloud "will be output and you have successfully completed a call to the speech recognition service.
Brief introduction of 3.2 demo Project
3.2.1 Sending voice requests
Processed by the Asrdemo.java method Startasr (), the voice data is extracted first, and then a speech recognition request is created to send the extracted voice in batches to the server.
The benefit of sending in batches is that the server can begin processing recognition while you are in the process of voice collection, so that when the voice ends, it can get the fastest recognition result and return.
3.2.2 Receiving speech recognition results
Processed by Asrdemo.java's callback method onmessagereceived () to listen for the return of the server, in which the service side returns the following JSON field parameters for the recognition result:
{
"status" : "1",// 服务器状态,0为失败,非零为成功
"id" : "",
"finish" : "1",// 0为未结束,非零为结束,识别是否已经结束
"results" : {
"asr_out" : {
"result" : "你好小云",// 语音识别结果
"status" : 1,
"finish" : 1,
"version" : "4.0"
},
"out" : {}//保留字段
},
"bstream_attached" : false,
"version" : "4.0"
}
parameter, you can focus on the field asr_out, where "result": "Hello Little Cloud" is the result of speech recognition.
Ali number Plus (1-2) API call Analysis