簡體   English   中英

Python 3 中沒有帶有 pyttsx3 庫的音頻(無錯誤)

[英]No Audio with pyttsx3 Library in Python 3 (No errors)

在 Windows 10 上的 Visual Studios Code 上使用 pyttsx3(試用版本 2.5 到當前版本)和 Python 3.10.0。 我目前遇到的問題是代碼將運行,但沒有輸出音頻。 調試時沒有暫停進入或越過代碼(對於包括 pyttsx3 在內的部分)。 我確定我的音頻已打開,並且可以正常工作。 我使用了不同的 tts 庫 gtts 並且音頻有效,但我正在嘗試離線編寫。 我還在 PyCharm 的 VS 代碼中嘗試了這個確切的代碼,但我仍然遇到同樣的問題。 再次沒有錯誤或警告。

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% 錯了。

您忘記在engine.runAndWait上加上括號。 這樣做: engine.runAndWait()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM