First search http://ai.baidu.com/to enter the official website.
Drop down to find Baidu voice:
Then create a voice app:
After you manage your app:
Speech synthesis:
Then create a new py file:
fromAipImportaipspeechapp_id='14454183'Api_key='TXNUGCISENVEB93I70ESWWB4'Secret_key='Dzdok3dcueuxe28atfgioqzxvd91bmqu'Client=Aipspeech (app_id, Api_key, Secret_key) Res= Client.synthesis ('If I love you', options={ "Vol.": 8, "Pit": 8, "SPD": 5, "per": 4}) with open ("Audio.mp3",'WB') as F:f.write (res)
Speech recognition:
To save an audio file locally, create a new py file:
fromAipImportAipspeechImportosapp_id='14454183'Api_key='TXNUGCISENVEB93I70ESWWB4'Secret_key='Dzdok3dcueuxe28atfgioqzxvd91bmqu'Client=Aipspeech (app_id, Api_key, Secret_key)defget_file_content (filePath):" "because only PCM-formatted audio is recognized, the MP3 format is converted to PCM format using FFmpeg" "Cmd_str="ffmpeg-y-i {0}-acodec pcm_s16le-f s16le-ac 1-ar 16000 {0}.pcm". Format (FilePath) Os.system (CMD_STR) with open ("%S.PCM"% (FilePath),'RB') as F:returnF.read () Res= Client.asr (Speech=get_file_content ("Audio.mp3"), options={ "Dev_pid": 1536,})Print(RES)
Remember to place the bin directory in the Ffpeg in the system environment variable, and then restart Pycharn.
Then we write a demo:
Falsk Basic speech recognition and speech synthesis ()