【问题标题】:How to Resolve this code which is given below如何解决下面给出的代码
【发布时间】:2023-02-21 00:34:53
【问题描述】:
import os
from tkinter import *
from gtts import gTTS
from playsound import playsound

root = Tk()
root.geometry("350x300")
root.configure(bg='ghost white')
root.title("DataFlair - TEXT TO SPEECH")
Label(root, text="TEXT_TO_SPEECH", font="arial 20 bold", bg='white smoke').pack()
Label(text="DataFlair", font='arial 15 bold', bg='white smoke', width='20').pack(side='bottom')

Msg = StringVar()
Label(root, text="Enter Text", font='arial 15 bold', bg='white smoke').place(x=20, y=60)

entry_field = Entry(root, textvariable=Msg, width=50)
entry_field.place(x=20, y=100)


def Text_to_speech():
    message = entry_field.get()
    speech = gTTS(text=message)
    speech.save('DataFlair.mp3')
    playsound('DataFlair.mp3')
    os.remove('DataFlair.mp3')


def Exit():
    root.destroy()


def Reset():

    Msg.set("")


Button(root, text="PLAY", font='arial 15 bold', command=Text_to_speech, width='4').place(x=25, y=140)

Button(root, font='arial 15 bold', text='EXIT', width='4', command=Exit, bg='OrangeRed1').place(x=100, y=140)

Button(root, font='arial 15 bold', text='RESET', width='6', command=Reset).place(x=175, y=140)

root.mainloop()

在上面的代码中,可以在下一次显示错误时播放一次“DataFlair.mp3”(与存储主程序的文件夹相同)

Error 259 for command:
        play DataFlair.mp3 wait
    The driver cannot recognize the specified command parameter.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\benof\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "F:\pyprojects\voicereg\main.py", line 24, in Text_to_speech
    playsound('DataFlair.mp3')
  File "F:\voicereg\lib\site-packages\playsound.py", line 73, in _playsoundWin
    winCommand(u'play {}{}'.format(sound, ' wait' if block else ''))
  File "F:\voicereg\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException: 
    Error 259 for command:
        play DataFlair.mp3 wait
    The driver cannot recognize the specified command parameter.

如何在 python 中修复此错误 259。

尽快提供解决方案。

【问题讨论】:

    标签: python python-3.x google-app-engine


    【解决方案1】:
    from pydub.playback import play
    
    # ...
    
    def Text_to_speech():
        message = entry_field.get()
        speech = gTTS(text=message)
        speech.save('DataFlair.mp3')
        play(sound='DataFlair.mp3')
        os.remove('DataFlair.mp3')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多