百度人工智能
百度人工智能
- 百度语音
from aip import AipSpeech
# //ai.baidu.com/ai-doc/SPEECH/Gk4nlz8tc
""" 你的 APPID AK SK """
APP_ID = 'xxxx'
API_KEY = 'xxx'
SECRET_KEY = 'xxx'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# print(client)
result = client.synthesis('来了,老弟', 'zh', 1, {
'vol': 5,
'per': 4,
'spd': 3,
'pit': 7
})
# print(result)
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
with open('audio.mp3', 'wb') as f:
f.write(result)
- 语音识别
from aip import AipSpeech
# //ai.baidu.com/ai-doc/SPEECH/Gk4nlz8tc
""" 你的 APPID AK SK """
APP_ID = 'xxx'
API_KEY = 'xxx'
SECRET_KEY = 'xxx'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# print(client)
# 读取文件
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
# 识别本地文件
result = client.asr(get_file_content('audio.pcm'), 'pcm', 16000, {
'dev_pid': 1537,
})
print(result.get('result')[0])
ffmpeg源码安装
sudo apt install ffmpeg
ffmpeg -y -i audio.wav -acodec pcm_s16le -f s16le -ac 1 -ar 16000 audio.pcm