aidygus / LinVAM

Linux Voice Activated Macro
GNU General Public License v3.0
58 stars 6 forks source link

Invalid Sample Rate under Linux Mint w/sudo #7

Open nictheman123 opened 3 years ago

nictheman123 commented 3 years ago

OS: Linux Mint 20.1 Ulyssa Python: Python 3.8.5 All python packages installed through pip3, all necessary libraries installed via apt, I have double checked they are all the latest version.

Environment established, I mostly use the -noroot flag, as I don't like handing over root control unless I need to. Unfortunately I have noticed it is less than reliable with Elite Dangerous, there will be times the script will claim it has pressed a key, but the game will not respond for some reason. This could be due to a number of issues in the script or my own proton setup, it's hard to determine.

So, I decided to attempt the root method. I followed the steps exactly, and this is the output I get:

SoundFiles: init
SoundFiles: scanning
ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
Expression 'PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2718
Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2842
Traceback (most recent call last):
  File "./main.py", line 332, in <module>
    mainWnd = MainWnd()
  File "./main.py", line 26, in __init__
    self.m_profileExecutor = ProfileExecutor(None, self)
  File "/home/nick/Downloads/git-repos/LinVAM/profileexecutor.py", line 33, in __init__
    self.m_stream = self.m_pyaudio.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True)
  File "/usr/local/lib/python3.8/dist-packages/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9997] Invalid sample rate

My instinct says this is an issue of pulseaudio not playing nice under sudo, but I haven't found a reason that would be, much less a fix.

I may create a branch on my local and attempt to fix this if I find something that looks useful, but until then, the report is here.

smirgol commented 3 years ago

Ah yes, xdotool, which is used when not running as root, unfortunately isn't that reliable. It works quite okay, but sometimes it fails for no reason. Have not figured out yet why, unfortunately.

You can run it as root, there shouldn't be any problems as the code is not doing anything harmful, but I understand that this is not something you want to do. But some things are difficult to do without root privileges, as you need to interact with a different application and usually that's not something you are easily allowed to do with normal user privileges.

I also get a lot of errors when running as root and at some point I gave up trying to fix it for me, that's why I've implemented the -noroot option. I'll see if I can fix that issue, but I have other issues when running as root and don't get as far as you do, yet. :)

If you make any progress and/or find a fix, please let us know! :) Thank you.

Pragmer commented 1 year ago

I ran into the same issue and made another issue post. I also did some digging on the "Invalid sample rate" error and found out that the problem is likely that the requested microphone audio sample rate from the script is different from the audio sample rate that the microphone is using. Unfortunately I have no idea how to read code nor do I know which file to look into. From my limited knowledge it seems like the solution would be to either edit the requested sample rate from the script, or edit the sample rate of the microphone itself. How one would go about doing that I do not know. Nor do I know for certain if this actually IS the solution as I am not a coder, merely did some internet searching.

smirgol commented 1 year ago

Please try if this fixes the issue for you: https://github.com/smirgol/LinVAM/tree/fix-samplerate