I'm trying to use the microphone of my webcam logitech to listen
with sr.Microphone(sample_rate=32000) as source:
...
This error occurs :
File "/home/pi/project2/interface.py", line 226, in listen
with sr.Microphone(sample_rate = 32000) as source:
File
"/usr/local/lib/python3.4/dist-packages/speech_recognition/init.py",
line 140, in enter
input=True, # stream is an input stream File "/usr/local/lib/python3.4/dist-packages/PyAudio-0.2.10-py3.4-linux-armv7l.egg/pyaudio.py",
line 750, in open
stream = Stream(self, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/PyAudio-0.2.10-py3.4-linux-armv7l.egg/pyaudio.py",
line 441, in init
self._stream = pa.open(**arguments) OSError: [Errno -9999] Unanticipated host error
I didn't find any fitting information on the web
You may check your anti-virus SW.
I got the same problem "OSError: [Errno - 9999] Unanticipated host error" every time I tried to record the wave file by pyAudio.
I check and confirm all the parameters OK.
I was stuck for several days before I noticed the anti-virus on my PC block my python script call to the hardware level.
All the thing I need to do is disable or exit the anti-virus SW and everything work well again.
I got this error while working with python threads.
I was creating 2 pyaudio objects for different purposes and hadn't closed one of them later. This gave me the error:
[Errno - 9999] Unanticipated host error
Closing that thread fixed my issue.
It may be a problem with microphone permission for your app make sure you have enabled the microphone permission for all apps in settings. because have developed one Tkinter project in which I am using pyaudio for recording purpose. On my pc the recorder working fine but not on the client machine. after investigation and running the same script on client machin it gives the same error as you mention. but after giving permission of a microphone for my project it working fine.
pyaudio throws this error because the python script not able to use the mic hardware.
I hope you will get some clarity with this and my answer may help you.
Windows user here. For me, I just had to change the default microphone which was being changed every time I connected my headphones.
This might also happen if there is no microphone access to the program or the microphone is not working properly. To check if the microphone is working properly, try recording some audio in voice recorder, and see if the selected microphone is the default audio recording device.
Related
I am working with a Keysight waveform generator and pyVisa and I notice that if my code doesn't complete successfully and ends I need to perform a hard reset of the device to attempt my code again.
I have tried resetting the device under the __del__ method so that the device is in a known state but that doesn't seem to work. I've also tried using pyvisa.resources.SerialInstrument.clear(). Has anyone else had a problem like this and how did you solve it?
The host computer is running windows 7. PyVISA version is 1.8. After the program fails by me cancelling the python script I will try to send a simple *IDN? SCPI command to the device and I get error:
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.
If I try to call pyvisa.resources.SerialInstrument.clear() on the device I get error
pyvisa.errors.VisaIOError: VI_ERROR_INV_SETUP (-1073807302): Unable to start operation because setup is invalid (usually due to attributes being set to an inconsistent state).
The problem was that the device was still being connected to by another instance. The cause of that was because running visa.ResourceManager().list_resources() was listing the device twice, once as a USB device and also as an ASRL.
The solution was to call visa.ResourceManager().list_resources(query='USB?*') to make sure that the instrument is only listed once in my results. (Alternately, I could have disabled USB or GPIB in the device settings.) Then call device.clear() immediately after opening the resource to make sure that the buffers were empty because at the error there might have been unread data there. This solved the problem.
Working on trying to get serial comminications working between an arduino and my computer. When working off the code that can be seen here I keep getting this error:
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM4': WindowsError(5, 'Access is denied.')
I have edited the com port used in the aformentioned code to match what I am actually using, but I cant get this error to go away. Here are a few thinks I've tried:
Ran file as administrator
Started pycharm as administrator
Changed the security properties for the directory the program is in
Unistalled and reinstalled the COM port in device manager
Restarted Computer
The weird thing is sometimes after I do these fixes it will work once, and then when I stop the program and start it again it once again throws the error.
Ran into the same problem before and I realized that I left the serial connection open after serial read program execution completed. Closing the serial connection once done should work.
import serial
serial = serial.Serial('COM124', baudrate=115200, timeout=1)
#Main function to do something
my_function():
...
#end of Main function
my_function()
#adding below line will solve your problem
serial.close()
I am new to python and am trying to run a prewritten program but keep recieving an error here is the whole error.
Traceback (most recent call last):
File "C:\source\python\pill.py", line 29, in <module>
ser.open()
File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 66, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
SerialException: could not open port 'COM7': WindowsError(5, 'Access is denied.')
I am the admin as well
You may have another program using the COM port, for example a test program like firmata_test.exe that our course work told use to use.
One course module told us to run that program, which is a Windows executable that opens the COM port and monitors the various pins on the board and lets us toggle their state High or Low. The next module told us to run some Python code in the IDLE code editor that would connect to the board and write to the pin state to turn an LED on and off. The Python code failed with the Access is denied message, because the COM port was already in use by firmata_test.exe, though the error message did not mention this specifically (because the Python code did not know why it could not open the port, only that it could not).
Close any other software such as firmata_test.exe that may be using the COM port and run your Python code again.
I am using a telit he910g card. it is connected to my PC directly using a miniPCI slot.
I am using it for 3G internet connection and A-GPS/GPS services.
My system is running linux mint 17.1, the 3G connection is handled using the network manager APP and works great. The 3G connection is started and handled using a module that is part of a program I am writing.
The code I am using in order to connect to the serial port is this:
def _connect_to_device(self):
""" Connect to a serial port """
try:
self._device = serial.Serial(self._filename, baudrate=self._baud_rate)
except StandardError, e:
raise StandardError("Couldn't connect to GPS device. Error: %s" % str(e))
When I use the python program alone it works great. But when I try and use it while the 3G is on i cant connect to the serial device. The wierd thing is that if I try to connect to it using a program like "minicom" while 3G is turned on it DOES work.
So my question is: how can I make both run and work together? since now they are mutually exclusive.
thanks to all who help. :)
Glad you found a way round your problem. Just for completeness:
Normally, serial ports can be opened by multiple processes.
If one of them does ioctl(,TIOCEXCL) on the open file then further opens will return EBUSY until everyone closes the device. Only root can get past this and open the device at all times.
If root opens the device and does an ioctl(,TIOCNXCL), then other processes can open the device too.
In python, TIOCNXCL isnt defined anywhere, but you can do the ioctl (eg on stdin) with:
import fcntl
TIOCEXCL = 0x540c # from /usr/lib64/perl5/asm-generic/ioctls.ph
TIOCNXCL = 0x540d
print fcntl.ioctl(0, TIOCNXCL)
Ok, so it is solved.
the issue was that the telit module has 2 ports /dev/ttyACM0 (high speed) and /dev/ttyACM3 (lower speed).
I tried to connect to the high speed one, but apparently the 3G uses that one and it causes contentions.
So moving to use the lower speed port in my script solved the issue.
I'm trying to write a streaming audio client and I'd like to use ossaudiodev functions to help me play back the audio on my local machine. Unfortunately, I'm getting an exception every time I try to run my code:
Unhandled exception in thread started by <function audioplayer at 0x88e96f4>
Traceback (most recent call last):
File "client.py", line 56, in audioplayer
audio = ossaudiodev.open("/dev/audio", 'w')
IOError: [Errno 16] Device or resource busy: '/dev/audio'
Here's my code. Pretty simple methinks, but not sure how to free up the /dev/audio resource.
def audioplayer():
audio = ossaudiodev.open("/dev/audio", 'w')
audio.setfmt(ossaudiodev.AFMT_MU_LAW)
audio.channels(2)
audio.speed(8000)
packet = 0
sleep(.20) # give it a little bit of time to fill ze buffers
while (packets[packet] != "\0"):
audio.write(packets[packet])
packet += 1
Any tricks to this?
Edit: The answer is obvious and stupid. I was playing pandora while running the code, thus the speakers were "busy" doing that. Can anyone clarify why this is so? How can other applications all run multiple audio streams at the same time, yet I seemingly can't?
Even on systems where it's available, the OSS interface is usually just a facade over ALSA. Consider using a library that supports multiple interfaces, such as pyao.
your desktop manager is already using your soundcard, you may have more luck with dmix plugin for alsa, but it's often difficult
soundblaster live has hw mixing so you can open it multiple times
and yes definitively you can find a working backend of pyao