题目: 请应用百度云提供的语音相关API完成以下内容:
1. 自行注册相关账号,并建立应用;
2. 阅读相关语音解析文字和文字合成语音的相关API文档;
3. 解析“16k-23850.amr”语音文件内容,并将返回值“{'corpus_no': '6568285558591004267', 'err_msg': 'success.', 'sn': '182861598861529298154', 'result': ['北京科技馆,'], 'err_no': 0}”,提取出对应的中文,即“北京科技馆”,注你可以应用以前学习的所有知识,关于字符处理相关函数请自行查阅相关资料;
4. 请应用语音合成函数,合成包括你们小组所有人员名字和你们小组的口号,要求用男播音员的口音。
语音识别:
from
aip
import
AipSpeech
""" 你的 APPID AK SK """
APP_ID
=
''
API_KEY
=
''
SECRET_KEY
=
''
client
=
AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# 读取文件
def
get_file_content
(
filePath
):
with
open
(filePath,
'rb'
)
as
fp:
return
fp.read()
# 识别本地文件
rtn
=
client.asr(get_file_content(
'16k-23850.amr'
),
'amr'
,
16000
, {
'dev_pid'
:
1536
,
})
print
(rtn[
'result'
][
0
])
语音合成:
from
aip
import
AipSpeech
""" 你的 APPID AK SK """
APP_ID
=
''
API_KEY
=
''
SECRET_KEY
=
''
client
=
AipSpeech(APP_ID, API_KEY, SECRET_KEY)
str_1
=
'''
岁月是一条趟过青春的河
'''
result
=
client.synthesis(str_1,
'zh'
,
1
, {
'vol'
:
5
,
'per'
:
4
,
'spd'
:
2
,
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if
not
isinstance
(result,
dict
):
with
open
(
'auido.mp3'
,
'wb'
)
as
f:
f.write(result)