aidygus / LinVAM

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

Unable to run the script. #12

Closed Pragmer closed 1 year ago

Pragmer commented 1 year ago

Probably relevant info: I am using Linux Mint 21.1 Cinnamon, Kernel version 5.19.0-45-generic.

I installed everything as the main page instructs, ran into some issues, and got further by installing the packages through the package manager rather than pip3. After getting everything to install(including the parts labeled optional) I tried both methods of usage(root and non root). Both methods spat out different errors at me and did not run.

The ROOT method spat out:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
SoundFiles: init
SoundFiles: scanning
No folder 'voicepacks' found. Please create one and copy all your voicepacks in there.
ALSA lib pcm_dsnoop.c:601:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
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 confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib pcm_dsnoop.c:601:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
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 "/home/leaderofthe00fkins/LinVAM/./main.py", line 332, in <module>
    mainWnd = MainWnd()
  File "/home/leaderofthe00fkins/LinVAM/./main.py", line 26, in __init__
    self.m_profileExecutor = ProfileExecutor(None, self)
  File "/home/leaderofthe00fkins/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/lib/python3/dist-packages/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9997] Invalid sample rate

The second method spat out:

Traceback (most recent call last):
  File "/home/leaderofthe00fkins/LinVAM/./main.py", line 6, in <module>
    from profileeditwnd import ProfileEditWnd
  File "/home/leaderofthe00fkins/LinVAM/profileeditwnd.py", line 7, in <module>
    from profileexecutor import *
  File "/home/leaderofthe00fkins/LinVAM/profileexecutor.py", line 8, in <module>
    from pocketsphinx.pocketsphinx import *
ModuleNotFoundError: No module named 'pocketsphinx.pocketsphinx'

Not sure why I would have an "Invalid sample rate". Nor did I find a package or really anything called "pocketsphinx.pocketsphinx".

Pragmer commented 1 year ago

I 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

As for the second problem: I've created a testbranch where I have fixed that. If you could check that out and leave a reply if it works for you, that'd be great! https://github.com/smirgol/LinVAM/tree/testbranch

As for the sample rate issue, I have to look into that. It's a bit difficult, as I don't get that error, but I'll try.

smirgol commented 1 year ago

On top of the fix above, I've added something that might fix the samplerate issue. https://github.com/smirgol/LinVAM/tree/fix-samplerate

Pragmer commented 1 year ago

Update: I git cloned both and tested them out, the -noroot fix in the testbranch did work, the program ran, although I haven't the time to test it out on an application atm. The samplerate fix gave me a different error when I ran it however.

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
SoundFiles: init
SoundFiles: scanning
No folder 'voicepacks' found. Please create one and copy all your voicepacks in there.
Traceback (most recent call last):
  File "/home/leaderofthe00fkins/LinVAM/./main.py", line 332, in <module>
    mainWnd = MainWnd()
  File "/home/leaderofthe00fkins/LinVAM/./main.py", line 26, in __init__
    self.m_profileExecutor = ProfileExecutor(None, self)
  File "/home/leaderofthe00fkins/LinVAM/profileexecutor.py", line 24, in __init__
    self.m_config = Config(
  File "/usr/lib/python3/dist-packages/sphinxbase/sphinxbase.py", line 84, in __init__
    raise AttributeError("No constructor defined")
AttributeError: No constructor defined

So the only part of this error that I can understand is that it doesn't like that I have no voicepacks folder. The rest of it I have no clue. I could speculate and say that this output is telling you which lines to look at in which files, but I don't actually know if that's what its doing or not.

smirgol commented 1 year ago

Thank you for the feedback, much appreciated!

Hm, the problem isn't related to missing voicepacks, I should have made that message more clearer when adding that feature, sorry.

I'm a little bit puzzled about that error message, as it complains about a part of the code, that can be found in both test branches, testbranch and fix-samplerate...

But as I can see you did run it with root permissions in that case, and my best guess is that the pocketsphinx python package installed for the root user is of an older version than the one installed for your regular user. The change I've made is required for the newer version of pocketsphinx, but likely does not work on older versions. Maybe a sudo pip install --upgrade pocketsphinx can fix it?

Pragmer commented 1 year ago

So I have now managed to get the program open with both methods(not both at the same time). I managed to get the noroot version working. I created a profile named "Test" and created a new command with the word to listen for as "test" with the input being "a". I clicked ok until I got back to the main program, clicked enable listening, and it worked just fine. The samplerate fix version with the sudo however did not function properly. It opened the application and let me navigate the menus and create a profile, BUT it never actually functioned, and actually crashed multiple times. As far as I'm concerned I'm good to go since the noroot seems to be working fine, but I'm sure that you'd like to figure out whats going on and potentially fix the sudo version so I copied the terminal output of the most successful attempt and pasted it below.

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
SoundFiles: init
SoundFiles: scanning
No folder 'voicepacks' found. Please create one and copy all your voicepacks in there.
ALSA lib pcm_dsnoop.c:601:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
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 confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib pcm_dsnoop.c:601:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
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
Detection started
Exception in thread Thread-17 (doListen):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/profileexecutor.py", line 101, in doListen
    buf = self.m_stream.read(1024)
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 608, in read
    return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9981] Input overflowed
Traceback (most recent call last):
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/./main.py", line 276, in slotListeningEnabled
    self.m_profileExecutor.setEnableListening(False)
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/profileexecutor.py", line 94, in setEnableListening
    self.stop()
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/profileexecutor.py", line 131, in stop
    self.m_stream.stop_stream()
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 524, in stop_stream
    pa.stop_stream(self._stream)
OSError: Stream not open
Detection started
Exception in thread Thread-18 (doListen):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/profileexecutor.py", line 101, in doListen
    buf = self.m_stream.read(1024)
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 608, in read
    return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9988] Stream closed
Traceback (most recent call last):
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/./main.py", line 220, in slotProfileChanged
    self.m_profileExecutor.setProfile(self.m_activeProfile)
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/profileexecutor.py", line 76, in setProfile
    self.stop()
  File "/home/leaderofthe00fkins/LinVAM-fix-samplerate/profileexecutor.py", line 131, in stop
    self.m_stream.stop_stream()
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 524, in stop_stream
    pa.stop_stream(self._stream)
OSError: Stream not open

This is everything that happened after opening the program with the command until I closed the program.

Pragmer commented 1 year ago

Now I just need to learn C# so I can make my weird ass Terraria mod.

smirgol commented 1 year ago

I'd say, if the -noroot version works for you, best stick to that. Running python as root is a bad idea overall, but in this case it was needed for the keyboard strokes. I've replaced the functionality for the keyboard strokes with something else, which does not require root, thus the -noroot option which activates this. It is a bit less reliable, but no root required. I never got the root version to work for me as well.

Maybe I can replace that root requiring part completely, it's a bit tricky though to not break existing configurations for those who already use it.

As for the error report which you kindly provided: I had that as well and I can suppress that error, but for me it still didn't work due to some audio issues, albeit it did no longer throw errors.