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

标签 python-3.x ubuntu speech-recognition

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

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/

相关文章:

python - 无法按名称访问列数据

python - 从字典调用的字符串是无效语法? -Python 3

Python 和 Ansible - 编解码器错误 UTF-8 到 ascii 转换

linux - 更新 Shiny 的服务器配置以更改超时错误

deep-learning - 为什么 Mel-filterbank 能量在使用 CNN 的语音命令识别方面优于 MFCC?

android - 为什么 AudioRecord 实例在先前停止后无法重新启动

python - 属性错误: 'NoneType' object has no attribute 'lower

python-3.x - 无法通过 ldap3 Python3 更改用户密码

python - Ubuntu 10.10 上的 virtualenvwrapper - Python

swift - OSX Sierra Nsspeechrecognizer 问题