name' wav_filename'未定义
def Text2Speech(file_name,InpText):
Mp3Extension=".mp3"
waveExtension=".wav"
mp3FilePath="C:\\Texttospeech\\"+file_name+Mp3Extension
waveFilePath="C:\\Texttospeech\\"+file_name+waveExtension
if os.path.isfile(waveFilePath):
PlaySound(waveFilePath);
else:
tts=gTTS(text=InpText,lang="en-us")
tts.save(mp3FilePath)
f = TemporaryFile();
tts.write_to_fp(f);
f.close();
subprocess.call(['C:\\Temp\\ffmpeg\\bin\\ffmpeg', '-i', mp3FilePath,mp3FilePath])
PlaySound(waveFilePath);
return;
def PlaySound (wavFile) :
chunk = 1024
try:
wf = wave.open(wavFile, 'rb')
except IOError as ioe:
sys.stderr.write('IOError on file ' + wav_filename + '\n' + \
str(ioe) + '. Skipping.\n')
return
except EOFError as eofe:
sys.stderr.write('EOFError on file ' + wav_filename + '\n' + \
str(eofe) + '. Skipping.\n')
return
# Instantiate PyAudio.
p = pyaudio.PyAudio()
stream = p.open(
format = p.get_format_from_width(wf.getsampwidth()),
channels = wf.getnchannels(),
rate = wf.getframerate(),
output = True)
data = wf.readframes(chunk)
while len(data) > 0:
stream.write(data)
data = wf.readframes(chunk)
答案 0 :(得分:0)
wav_filename
未在函数PlaySound
中定义。