代码部分:
# -*- coding: UTF-8 -*-
from aip import AipSpeech
from playsound import playsound
""" 你的 APPID AK SK """
APP_ID = '17311850'
API_KEY = '4uY0GkFIXXE7vDY0jBKDT44n'
SECRET_KEY = 'PNwRoSMswRzuKpEFjvGBpjelINT8FY49'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
result = client.synthesis("你好超哥,我是百度",'zh',1,{'vol':9,'spd':5,'pit':5,'per':4})
if not isinstance(result,dict):
with open('audio.mp3','wb') as f:
f.write(result)
playsound('audio.mp3')
参数说明部分:
推荐使用python进行语音播放的方法:
①使用playsound库
from playsound import playsound
playsound('xx.mp3')
②使用pygame库
from pygame import mixer
import time
mixer.init()
mixer.music.load('xx.mp3')
mixer.music.play()
time.sleep(5)
mixer.music.stop()
③使用mp3play库(仅支持python2,对python3不支持)
import mp3play
import time
clip = mp3play.load('xx.mp3')
clip.play()
time.sleep(5)
clip.stop()
④打开系统自带播放器,然后播放MP3,弹窗麻烦复杂
import os
os.system('xx.mp3')