speech_recognition icon indicating copy to clipboard operation
speech_recognition copied to clipboard

OSError: [Errno -9999] Unanticipated host error

Open dongzizhu opened this issue 4 years ago • 2 comments

It's killing me that a simple example of pyaudio couldn't work. I'm trying to record my voice using pyaudio like this:

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK)

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()

the error report like this: Traceback (most recent call last): File "D:/projects/recording/test.py", line 17, in frames_per_buffer=CHUNK) File "C:\Program Files\Python36\lib\site-packages\pyaudio.py", line 750, in open stream = Stream(self, *args, **kwargs) File "C:\Program Files\Python36\lib\site-packages\pyaudio.py", line 441, in init self._stream = pa.open(**arguments) OSError: [Errno -9999] Unanticipated host error

The strange thing is that this code work just fine on my other computer. I'm thinking maybe something's wrong with the mic. Thanks so much!

dongzizhu avatar Jul 10 '20 17:07 dongzizhu

did you solved? if you remember the solution 3 years after

GregCloudPark avatar May 15 '23 20:05 GregCloudPark

did you solved? if you remember the solution 3 years after

To be honest, no. But I didn't record this as a code problem in my notes, so I guess it's just a hardware problem like the setting of the mic or something. Good luck!

dongzizhu avatar May 24 '23 03:05 dongzizhu