from aip import AipSpeech
import os
import shutil
class getMp3(object):
"""docstring for getMp3"""
def __init__(self):
super(getMp3, self).__init__()
self.APP_ID = '25602943'
self.API_KEY = 'vyYLov63W6x33nIPvwVdLLsX'
self.SECRET_KEY = 'EzgQoFF9xp62SeGCXCBaD8FjWNxvl9kZ'
self.mp3Path = r'C:\Users\HK\Desktop\ speech recognition \sound2'
def main(self, text, filename, per):
client = AipSpeech(self.APP_ID, self.API_KEY, self.SECRET_KEY) # These three parameters need to be registered with Baidu AI Obtain through cloud platform
result = client.synthesis(text, 'zh', 1, {
'vol': 5,
'per': per
}) # For the text to be converted, fill in the first attribute in the brackets
# vol For volume ,per Is the sound category
# Recognize the correct return speech binary Error returns dict Refer to the following error code , Generating audio
if not isinstance(result, dict):
with open(filename, 'wb') as f:
f.write(result)
mp3Path Is the path to save the voice file ,main In the method ,filename Is the filename of the audio file ,per Is the sound type of the audio file
aip The installation of the package pip install baidu-aip==2.2.18.0