测试音频
注意事项
安装SDK可以直接pip安装 pip install baidu-aip 接口调用# 引入Speech SDKfrom aip import AipSpeechimport os path = 'D:/data/VoiceRecog/'os.chdir(path)# 定义常量APP_ID = '你的 App ID'API_KEY = '你的 API Key'SECRET_KEY = '你的 Secret Key'# 初始化AipSpeech对象aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)# 读取文件def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read()# 识别本地文件#aipSpeech.asr(get_file_content('demo0.wav'), 'wav', 16000, {'lan': 'zh',})#遍历文件夹中的wav并进行识别for dir in [x for x in os.listdir(path) if x[-1]=='v']: print dir try: t = aipSpeech.asr(get_file_content(dir), 'wav', 16000, { 'lan': 'zh',}) #print t print t['result'][0] except: print 'error ,pass' 识别结果:
|
|
来自: 新用户79878317 > 《聊天机器人》