Python 3 中的 pyttsx3 库没有音频(无错误)

发布于 2025-01-09 01:33:52 字数 1768 浏览 0 评论 0原文

使用 Python 3.10.0 在 Windows 10 上的 Visual Studios Code 上使用 pyttsx3(尝试过版本 2.5 到当前版本)。 我目前遇到的问题是代码将运行,但没有输出音频。调试时,不会暂停进入或越过代码(对于包括 pyttsx3 在内的部分)。我确保我的音频已打开并且正常工作。我使用了不同的 tts 库 gtts 并且音频有效,但我正在尝试离线编写。我还在 PyCharm 中尝试了来自 VS code 的确切代码,但仍然遇到同样的问题。再次没有错误或警告。

import speech_recognition as sr
import pyttsx3


listener = sr.Recognizer()
engine = pyttsx3.init(driverName='sapi5')
#voices = engine.getProperty('voices')
#engine.setProperty('voice', voices[0].id)
engine.say("Testing, audio")
engine.runAndWait

try:
    with sr.Microphone() as source:
        print('Listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
        engine.say(command)
        engine.runAndWait
except:
    pass

print('Hello')

我还尝试了这段没有驱动程序名称的代码块,上面同样的问题仍然存在。

import speech_recognition as sr
import pyttsx3


listener = sr.Recognizer()
engine = pyttsx3.init()
#voices = engine.getProperty('voices')
#engine.setProperty('voice', voices[0].id)
engine.say("Testing, audio")
engine.runAndWait

try:
    with sr.Microphone() as source:
        print('Listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
        engine.say(command)
        engine.runAndWait
except:
    pass

print('Hello')

两个程序上的两条注释行也没有为我带来任何改变。 我还仅使用 pyttsx3 测试了该程序。

import pyttsx3

engine = pyttsx3.init(driverName='sapi5')
engine.say("Testing, audio")
engine.runAndWait

并使用“测试,音频”而不是“测试,音频”进行测试,我也尝试了单个单词。

任何帮助都会很棒!谢谢你! 同时,我将尝试在 Linux 中测试这个(翻译为与 Linux 一起使用)程序,看看我的操作系统是否存在问题。 我还将尝试旧版本的 python,看看这是否是问题所在。与Python 2一起。 我最大的假设是 pyttsx3 需要较早版本的 python 才能工作,但我对此也可能是 100% 错误的。

Using pyttsx3 (tried versions 2.5 to current) on Visual Studios Code on Windows 10 With Python 3.10.0.
My Problem that I am currently having is that the code will run through, but no audio is being outputted. while debugging there is no pause stepping into or over the code (for parts including pyttsx3). I made sure my audio is on, and that it is working. I used a different tts library gtts and the audio worked, but I am trying to write offline. I also tried this exact code from VS code in PyCharm and I still had the same problem. Again with no errors or warnings.

import speech_recognition as sr
import pyttsx3


listener = sr.Recognizer()
engine = pyttsx3.init(driverName='sapi5')
#voices = engine.getProperty('voices')
#engine.setProperty('voice', voices[0].id)
engine.say("Testing, audio")
engine.runAndWait

try:
    with sr.Microphone() as source:
        print('Listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
        engine.say(command)
        engine.runAndWait
except:
    pass

print('Hello')

I also tried this block of code with no driver name and the same problem above persists

import speech_recognition as sr
import pyttsx3


listener = sr.Recognizer()
engine = pyttsx3.init()
#voices = engine.getProperty('voices')
#engine.setProperty('voice', voices[0].id)
engine.say("Testing, audio")
engine.runAndWait

try:
    with sr.Microphone() as source:
        print('Listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
        engine.say(command)
        engine.runAndWait
except:
    pass

print('Hello')

The two commented lines on both programs didn't change anything for me either.
I also tested the program with just pyttsx3.

import pyttsx3

engine = pyttsx3.init(driverName='sapi5')
engine.say("Testing, audio")
engine.runAndWait

and tested using 'Testing, audio' instead of "Testing, audio" and I tried single words as well.

Any help would be amazing! Thank you!
In the mean time I will try to test this(translated to work with Linux) program in Linux to see if my OS is the issue.
I will also try an older version of python to see if that is the issue. Along with python 2.
My biggest assumption is that pyttsx3 needs a earlier version of python to work, but I could also be 100% wrong about that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征﹌骨岁月お 2025-01-16 01:33:52

您忘记在 engine.runAndWait 上加上括号。执行以下操作:engine.runAndWait()

You forgot to put the parentheses on engine.runAndWait. Do this: engine.runAndWait()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文