""" 》》》运行前必做《《《 1. 运行【安装第三方库.py】文件 2. 注册百度云账号,获取API,配置后查看完整效果 账号注册指南: https://huewq7h021.feishu.cn/wiki/Ry3UwaoceiMRXgklbWtc9mEUn9f?from=from_copylink """ from aip import AipSpeech # 定义常量 APP_ID = '你的 AppID' API_KEY = '你的 API Key' SECRET_KEY = '你的 Secret Key' # 准备【语音识别器】 client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) # 定义要识别的语音文件 file = 'pyaudio.wav' # 读取音频文件 def read_audio(file): with open(file, 'rb') as f: return f.read() # 调用【语音识别器】 res = client.asr(read_audio(file), 'wav', 16000, { 'dev_pid': 1537 # 普通话识别 }) # 打印返回结果 if 'result' in res: print("识别结果:", res['result'][0]) else: print("识别失败:", res)