from aip import AipSpeech


# 读取语音文件数据
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


# 填写你的语音识别应用的App ID、API Key、Secret Key
APP_ID = ''
API_Key = ''
Secret_Key = ''
# 建立AipSpeech对象
client = AipSpeech(APP_ID, API_Key, Secret_Key)
# 调用百度AI的语音识别接口
fileName = input('输入语音文件名：')
filePath = './sound/' + fileName
result = client.asr(get_file_content(filePath), 'wav', 8000)
# 如果接口调用成功，输出文字，否则，输出错误原因
if result['err_no'] == 0:
    print(result['result'][0])
else:
    print('语音识别错误,原因:', result['err_msg'])


