文字识别,并转语音
from aip import AipSpeech
from aip import AipOcr
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('1.png')
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
# 调用通用文字识别, 图片参数为本地图片 ,未定义识别参数
result = client.basicGeneral(image)
list1 = result['words_result']
filename = '识别内容.text'
with open(filename,'w')as name:
for list2 in list1:
print(list2['words'])
name.write('\n'+list2['words'])
'''
for word in result['words_result']:
print(word['words'])
'''
client = AipSpeech(APP_ID,API_KEY,SECRET_KEY)
file1 = open('识别内容.text')
lan = file1.read() #word['words'] #"你好,我是百度助手"
result = client.synthesis(lan,'zh',1,{'vol':5,'per':4,'spd':5})
'''
spd语速,取值0-15,默认为5中语速(选填)
pit音调,取值0-15,默认为5中语调(选填)
vol音量,取值0-15,默认为5中音量(选填)
per发音人选择, 0为普通女声,1为普通男生,3为情感合成-度逍遥,
4为情感合成-度丫丫,默认为普通女声
'''
#识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result,dict):
with open('D:\Desktop\第六次作业操作1.mp3','wb') as f:
f.write(result)