A place to hold mainly reading notes, and some technical stuff occasionally. 这里主要是一些读书笔记、感悟;还有部分技术相关的内容。
目录[-]
调用百度语音识别API实现语音识别(ASR)与语音合成(TTS),分别需要发送一个HTTP请求。
Note: 在发送ASR或者TTS请求前,首先需要获取Access Token
;
获取Token 通过百度开发者账号获取到key与secret key,然后通过以下请求得到token;
//Access Token(每次获取后,有效期:一个月)
string getAccessUrl = $”https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id={speechModel.APIKey}&client_secret={speechModel.APISecretKey}”;
eg: https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=yourKey&client_secret=yourSecretKey
语音识别
//ASR: Automatic Speech Recognition(须在发送请求时写入音频数据)
string getTextUrl = $”http://vop.baidu.com/server_api?lan={speechModel.APILanguage}&cuid={speechModel.APIID}&token={speechModel.APIAccessToken}”;
eg: http://vop.baidu.com/server_api?lan=en&cuid=402&token=24.fd8c2088ac28b2722403c1acc36797e9.2592000.1487243775.282335-8317833
语音合成
//TTS: Text To Speech(直接返回.mp3)
string requestStr = $”http://tsn.baidu.com/text2audio?tex={text}&lan={speechModel.APILanguage}&per={speechModel.APIPerson}&ctp={speechModel.APIClientType}&cuid={speechModel.APIID}&tok={speechModel.APIAccessToken}&spd={speechModel.APISpeed}&pit={speechModel.APIPitch}&vol={speechModel.APIVolume}”;
eg: http://tsn.baidu.com/text2audio?tex=集齐五福,召唤神龙!&lan=zh&cuid=402&ctp=1&tok=24.fd8c2088ac28b2722403c1acc36797e9.2592000.1487243775.282335-8317833
程序界面:
If you have any questions or any bugs are found, please feel free to contact me.
Your comments and suggestions are welcome!