Been pulling my brains out for a few hours now, I cannot seem to get this working, I have been to the 3rd page of google results but I cannot seem to get this right.
code:
#!/bin/bash
python3.12 -m speech_recognition | while IFS= read -r x; do
case $x in
*"Got it"*)
echo "Action for text1"
ffplay -autoexit -nodisp -f lavfi -i 'sine=f=1200:d=0.05' && ffplay -autoexit -nodisp -f lavfi -i 'sine=f=1500:d=0.05' &
;;
*"You said"*)
echo "Action for text2"
espeak-ng "$x"
;;
*"test"*)
echo "Action for text3"
ffplay -autoexit -nodisp -f lavfi -i 'sine=f=1200:d=0.05' && ffplay -autoexit -nodisp -f lavfi -i 'sine=f=1200:d=0.05' &
;;
*)
echo "No match for $x"
# Optional default action for unmatched text
;;
esac
echo $x
done
terminal output:
usr_40476@2xeon:~/******/******> bash start.sh
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:878:(find_matching_chmap) Found no matching channel map
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2722:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:878:(find_matching_chmap) Found no matching channel map
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib dlmisc.c:339:(snd_dlobj_cache_get0) Cannot open shared library libasound_module_pcm_equal.so (/lib64/alsa-lib/libasound_module_pcm_equal.so: undefined symbol: snd_lib_error)
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave
^C^CException ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
usr_40476@2xeon:~/******/******>
I have tried the first three pages of google results and 7 chat sessions with various LLMs
while
loop is killed with Control-C, the pipe is closed and Python gets an error trying to write to stdout.try/except
inspeech_recognition
.signal.signal(signal.SIGINT, signal_handler)
(in python script) to handle Ctrl+C buttry/except
can be simpler. signals - Python: Catch Ctrl-C command. Prompt "really want to quit (y/n)", resume execution if no - Stack Overflow