Я полагаю, что именно этот модуль вызывает сбой моей программы и выдает эту ошибку: OSError: [Errno -9993] Недопустимая комбинация устройств ввода-вывода. Я обернул вызов к этому модулю в попытке, кроме блока SystemExit, и он все еще падал. Будем очень благодарны за любые идеи, как это исправить.
Я работаю на Ubuntu 18.04 в виртуальной среде Conda, используя Python 3.6.10.
###############################################################################################
######## STT SPEECH TO TEXT FUNCTION THAT RETURNS THE VARIABLE: command
import pyaudio
from vosk import Model, KaldiRecognizer
def myCommand():
# "listens for commands"
# We imported vosk up above.
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8000)
stream.start_stream()
model = Model("model-en")
rec = KaldiRecognizer(model, 16000)
while True:
data = stream.read(2000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
#print(rec.Result())
# I commented out this line and added the 3 lines below
myResult = rec.Result()
myList = myResult.split("text")
command = myList[1]
return command
######## END STT SPEECH TO TEXT FUNCTION THAT RETURNS THE VARIABLE: command
###############################################################################################
❯ pip list Версия пакета
beautifulsoup4 4.9.0
certifi 2020.4.5.1 chardet 3.0.4
нажмите 7.1.1
в будущем 0.18 .2
gTTS 2.1.1
gTTS-токен 1.1.3
idna 2.9
isort 4.3.21
lazy-object-proxy 1.4.3
mccabe 0.6.1
mock 4.0.1
MouseInfo 0.1.3
mypy 0.770
mypy-extensions 0.4.3
numpy 1.18.1
Pillow 7.1.1
pip 20.0.2
psutil 5.7.0
PyAudio 0.2.11
PyAuto GUI 0.9.50
PyGetWindow 0.0.8
pylint 2.4.4
PyMsgBox 1.0.7
pyperclip 1.8. 0
PyQt5 5.14.2
PyQt5-sip 12.7.2
PyRect 0.1.4
PyScreeze 0.1.26
python3 -xlib 0.15
PyTweening 1.0.3
запросы 2.23.0
setuptools 45.2.0
шесть 1.14.0
soupsieve 2.0
subprocess.run 0.0.8
typed-ast 1.4.1
набор расширений 3.7.4.1
urllib3 1.25.9
воск 0.3.3
колесо 0.34.2
википедия 1.4.0
завернутый 1.11.2
#
Я тоже ру Этот модуль не уверен на 100%, что является причиной проблемы, хотя я подозреваю, что первое:
###############################################################################################
######## TTS TEXT TO SPEECH FUNCTION
# This gets used all over to speak text aloud.
# It also prints to the console for people with bad memories.
from gtts import gTTS
import os
def talkToMe(mytext):
# "speaks audio passed as argument"
print(mytext)
# can handle multiline text.
#for line in mytext.splitlines():
# uses the google text to speech module to synthesize text
text_to_speech = gTTS(text=mytext, lang='en-uk')
# saves syntesized speech to audio.mp3
# this file gets written, played. and overwritten
# over and over again.
text_to_speech.save('audio.mp3')
# the sox modules wrapper is mpg123.
# This is called by the operating system imported os module.
os.system('mpg123 -q audio.mp3')
###############################################################################################
######## END TTS TEXT TO SPEECH FUNCTION
#
Here's what I'm seeing as error:
LOG (vosk[5.5.641~1-79319]:ComputeDerivedVars():ivector-extractor.cc:183) Computing derived variables for iVector extractor
LOG (vosk[5.5.641~1-79319]:ComputeDerivedVars():ivector-extractor.cc:204) Done.
LOG (vosk[5.5.641~1-79319]:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 1 orphan nodes.
LOG (vosk[5.5.641~1-79319]:RemoveOrphanComponents():nnet-nnet.cc:847) Removing 2 orphan components.
LOG (vosk[5.5.641~1-79319]:Collapse():nnet-utils.cc:1472) Added 1 components, removed 2
LOG (vosk[5.5.641~1-79319]:CompileLooped():nnet-compile-looped.cc:345) Spent 0.028789 seconds in looped compilation.
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection terminated
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1735
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1902
Expression 'PaAlsaStreamComponent_Initialize( &self->capture, alsaApi, inParams, StreamDirection_In, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2166
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2835
Traceback (most recent call last):
File "Juliet.py", line 376, in <module>
main()
File "Juliet.py", line 366, in main
output = mycommand.myCommand()[3:]
File "/home/bard/Code/Juliet/SpeakAndHear/mycommand.py", line 10, in myCommand
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8000)
File "/home/bard/miniconda3/envs/Juliet/lib/python3.6/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/home/bard/miniconda3/envs/Juliet/lib/python3.6/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9993] Illegal combination of I/O devices