Pet*_*ter 3 python mp3 pygame python-2.7 python-3.x
该程序仅运行两次。后来,错误发生。我不知道为什么它工作两次然后停止。
import tkinter, sys, pygame
from tkinter import messagebox
from gtts import gTTS
soundfile="file.mp3"
def ex():
sys.exit()
Run Code Online (Sandbox Code Playgroud)
主要问题在于:
def read():
t = e.get()
tts = gTTS(text=t, lang="en")
tts.save(soundfile)
pygame.mixer.init(frequency=16000, size=-16, channels=2, buffer=4096)
pygame.mixer.music.load(soundfile)
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.play(0,0.0)
while pygame.mixer.music.get_busy()==True:
continue
pygame.quit()
Run Code Online (Sandbox Code Playgroud)
接下来是按钮的代码。
def clear():
e.delete(0, 'end')
main = tkinter.Tk()
e = tkinter.Entry(main, justify = "center")
l = tkinter.Label(main, text = "Write text")
b1 = tkinter.Button(main, text = "Read", command = read)
b2 = tkinter.Button(main, text = "Clear", command = clear)
b3 = tkinter.Button(main, text = "Exit", command = ex)
Run Code Online (Sandbox Code Playgroud)
所以,我没有任何想法来解决它。
小智 6
from gtts import gTTS
import playsound
import os
x = ['sunny', 'sagar', 'akhil']
tts = 'tts'
for i in range(0,3):
tts = gTTS(text= x[i], lang = 'en')
file1 = str("hello" + str(i) + ".mp3")
tts.save(file1)
playsound.playsound(file1,True)
os.remove(file1)
Run Code Online (Sandbox Code Playgroud)
为每个对我有用的新保存重命名文件。
归档时间: |
|
查看次数: |
4016 次 |
最近记录: |