我正在尝试只播放 gTTs 的声音pygame.mixer.music.load()
。我不想将语音保存到文件中,所以我将其保存到BytesIO
流中。gTTs
返回.mp3
我知道支持有限的音频pygame
,因此我尝试将.mp3
音频转换为.wav
使用该pydub
模块,但是如果不将其保存到文件中,我找不到这样做的方法。我怎样才能以任何可能的方式解决这个问题?
from pygame import mixer
from gtts import gTTS
def play(buffer):
buffer.seek(0)
mixer.music.load(buffer) #Load the mp3
print("Sound loaded. Time to play!")
mixer.music.play() #Play it
def generate_voice(text, accent):
mp3_fp = BytesIO()
tts = gTTS(text)
tts.write_to_fp(mp3_fp)
return mp3_fp
text = "Hi there"
buffer = generate_voice(text, accent)
play(buffer)
返回的错误pygame.mixer.music.load()
:pygame.error: ModPlug_Load failed