How Python can implement the step-up explanation of Baidu's speech recognition API

Source: Internet
Author: User
This time to everyone to bring python how to achieve the Baidu speech recognition API Step-by-stage, Python implementation of the Baidu Speech recognition API notes, the following is the actual case, together to see.

The example of this article for everyone to share the Ython to implement the specific code of Baidu speech recognition for your reference, the specific content as follows

Detailed Baidu speech Recognition API documentation

Download the Python SDK first, which can be installed with Python setup.py install

# Introduce speech sdkfrom AIP import aipspeech# define Constants app_id = ' Your App ID ' Api_key = ' your API key ' Secret_key = ' Your SECRET key ' # Initialize AI Pspeech Object Aipspeech = Aipspeech (app_id, Api_key, Secret_key)

In the above code, the constant app_id created in the Baidu Cloud console, constants Api_key and Secret_key are created after the application, the system is assigned to the user, are strings, used to identify the user, for access to do signature verification, can be viewed in the AI Service Console application list.

Start recognition

Note:

Request Description:
1. The original voice recording format currently only supports the evaluation of Mono voice with 8k/16k sampling rate of 16bit bit depth
2. Compression format support: PCM (uncompressed), WAV, AMR
3. System support Language type: Chinese (en), Cantonese (CT), English (en).

# Read File def get_file_content (FilePath):  with open (FilePath, ' RB ') as FP:    return Fp.read () # recognize local file Aipspeech.asr ( Get_file_content (' audio.pcm '), ' PCM ', 16000, {  ' lan ': ' ZH ',}) # get file recognition from URL Aipspeech.asr ("', ' PCM ', 16000, {  ') URL ': ' HTTP://121.40.195.233/RES/16K_TEST.PCM ',  ' callback ': ' Http://xxx.com/receive ',})

return Result:

Successfully returned {  "Err_no": 0,  "err_msg": "Success.",  "Corpus_no": "15984125203285346378",  "sn": " 481d633f-73ba-726f-49ef-8659accc2f3d ",  " result ": [" Beijing Weather "]}//failed to return {  " Err_no ": $,  " err_msg ":" Data Empty. ",  " SN ": null}

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How Python invokes the API for smart reply functionality

How Python handles the dataframe time field

How Python reads text data and translates it into a dataframe format

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.