人工智能-调百度AI接口

1.登陆百度AI的官网

1在这里插入图片描述

2
1.注册:没有账号注册
2.创建应用

1在这里插入图片描述

3.创建应用

1在这里插入图片描述

4.查看应用的ID

1
5.Python代码
1
2
3
4
5
6
7
from aip import AipSpeech

APP_ID = “appid "
API_KEY=”**********"
SECRET_KEY="**************"

client = AipSpeech(APP_ID,API_KEY,SECRET_KEY)
6.语音识别
1
2
3
4
5
6

语音识别

def speech_sb(file_path_name):
os.system(f’ffmpeg -y -i {file_path_name}.m4a -acodec pcm_s16le -f s16le -ac 1 -ar 16000 {file_path_name}.pcm’)

with open(f'{file_path_name}.pcm', 'rb') as fp:
    return fp.read()

调用语音识别

ret = client.asr(speech_sb(‘123’), ‘pcm’, 16000, {
‘dev_pid’: 1536,
})
7.语音合成
1
2
3
4
5
6
7
8
9
#语音合成
def speech_hc(title,text):
# title是生成文件的标题,text是哟啊合成的文本
result = client.synthesis(text)
if not isinstance(result, dict):
with open(f’{title}.mp3’, ‘wb’) as f:
f.write(result)
return
else:
return result
8.自然语言处理加图灵机器人

1
2
3
4
5
6
7
8
9
10
11
12

自然语音的处理

def my_npl(text,id):
#传入要对比的文本,id主要用于图灵机器人,
print(nlp_client.simnet(text,“你叫什么名字”).get(‘score’))
if nlp_client.simnet(text,“你叫什么名字”).get(‘score’)>=0.7:
ret_name = “我是Sopython,Sopython就是我”
return ret_name
else:
ret_tj = tuling(text,id)
if isinstance(ret, dict):
ret_tj = ret_tj.get(“results”)[0].get(“values”).get(‘text’)
print(ret_tj)
return ret_tj

#{‘corpus_no’: ‘6672231296183866724’, ‘err_msg’: ‘success.’, ‘err_no’: 0, ‘result’: [‘叫什么名字’], ‘sn’: ‘90391695291553499907’}
ret = my_npl(ret.get(‘result’),132) # 调用完语音识别之后,获取到识别的结果传入自然语言处理,id=132

如果自定义的自然语言处理成功的话,那么就返回自定的结果,否则的话调用图灵机器人来回答问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI_wx_3307623172

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值