gpt4 book ai didi

python-3.x - python3 错误 JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1,在 Ubuntu 中跳过解锁

转载 作者:行者123 更新时间:2023-12-04 18:50:34 28 4
gpt4 key购买 nike

我正在尝试进行语音识别,但每次运行时都会出现此错误。

JackShmReadWritePtr::~JackShmReadWritePtr - 未完成 -1 的初始化,跳过解锁

这是我的代码。

from gtts import gTTS
import playsound as ps
import speech_recognition as sr

sr.Microphone.list_microphone_names()

text=('text')
mic = sr.Microphone(device_index=20)
r = sr.Recognizer()

with mic as source:
audio = r.listen(source)

re = r.recognize_google(audio)

def rSpeak():
tts = gTTS(text)
tts.save('hello.mp3')
ps.playsound('hello.mp3', True)
rSpeak()

非常感谢任何帮助

最佳答案

你应该试着用这个说话:

import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
speak('Hello, Sir.')

如果您想识别声音,请使用以下命令:
import speech_recognition as sr 
def takeCommand():
#It takes microphone input from the user and returns string output
r = sr.Recognizer()
with sr.Microphone() as mic:
print("Listening...")
r.adjust_for_ambient_noise(mic)
audio = r.listen(mic)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception:
print("Say that again please...")
return "None"
return query

query = takeCommand().lower() #lower() is used to keep all your queries in lowercase.

然后你可以匹配你的查询变量来匹配你想要遵循的命令。

关于python-3.x - python3 错误 JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1,在 Ubuntu 中跳过解锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57212172/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com