Ali number Plus (1-2) API call Analysis

Source: Internet
Author: User

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.

  1. NlsRequest req = new NlsRequest();
  2. req.setApp_key("app_key"); // 替换为选定的app_key
  3. req.setAsr_sc("pcm"); // 这里为测试准备的语音文件是pcm语音文件。
  4. 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:

  1. {
  2. "status" : "1",// 服务器状态,0为失败,非零为成功
  3. "id" : "",
  4. "finish" : "1",// 0为未结束,非零为结束,识别是否已经结束
  5. "results" : {
  6. "asr_out" : {
  7. "result" : "你好小云",// 语音识别结果
  8. "status" : 1,
  9. "finish" : 1,
  10. "version" : "4.0"
  11. },
  12. "out" : {}//保留字段
  13. },
  14. "bstream_attached" : false,
  15. "version" : "4.0"
  16. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.