将音频文件保存到所需路径
Save audio file to desired path
我有很多需要保存的文本转语音音频文件,但这些文件经常会丢失。
目前我正在使用
import gtts
from playsound import playsound
def say(speech):
tts = gtts.gTTS(speech)
tts.save("audio.mp3")
playsound("audio.mp3")
有什么方法可以把mp3保存到我想要的地方吗?
您可以将新音频文件的内容粘贴到另一个文件中,如下所示:
import gtts
from playsound import playsound
def say(speech):
tts = gtts.gTTS(speech)
tts.save("audio.mp3")
playsound("audio.mp3")
# PLACE CONTENT INTO NEW FILE => S T A R T
main_file = open("audio.mp3", "rb").read()
dest_file = open('path/to_your/file_name.mp3', 'wb+')
dest_file.write(main_file)
dest_file.close()
# PLACE CONTENT INTO NEW FILE => E N D
或
import gtts
from playsound import playsound
import shutil
def say(speech):
tts = gtts.gTTS(speech)
tts.save("audio.mp3")
playsound("audio.mp3")
# PLACE CONTENT INTO NEW FILE => S T A R T
shutil.move("audio.mp3", "path/to_your/file_name.mp3")
# PLACE CONTENT INTO NEW FILE => E N D
我喜欢这样:s.save("你的文件夹 name/audio.mp3")
我有很多需要保存的文本转语音音频文件,但这些文件经常会丢失。 目前我正在使用
import gtts
from playsound import playsound
def say(speech):
tts = gtts.gTTS(speech)
tts.save("audio.mp3")
playsound("audio.mp3")
有什么方法可以把mp3保存到我想要的地方吗?
您可以将新音频文件的内容粘贴到另一个文件中,如下所示:
import gtts
from playsound import playsound
def say(speech):
tts = gtts.gTTS(speech)
tts.save("audio.mp3")
playsound("audio.mp3")
# PLACE CONTENT INTO NEW FILE => S T A R T
main_file = open("audio.mp3", "rb").read()
dest_file = open('path/to_your/file_name.mp3', 'wb+')
dest_file.write(main_file)
dest_file.close()
# PLACE CONTENT INTO NEW FILE => E N D
或
import gtts
from playsound import playsound
import shutil
def say(speech):
tts = gtts.gTTS(speech)
tts.save("audio.mp3")
playsound("audio.mp3")
# PLACE CONTENT INTO NEW FILE => S T A R T
shutil.move("audio.mp3", "path/to_your/file_name.mp3")
# PLACE CONTENT INTO NEW FILE => E N D
我喜欢这样:s.save("你的文件夹 name/audio.mp3")