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