0

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

6
  • When the while loop is killed with Control-C, the pipe is closed and Python gets an error trying to write to stdout.
    – Barmar
    Commented Feb 21 at 23:06
  • 1
    If you want to handle this more gracefully, use try/except in speech_recognition.
    – Barmar
    Commented Feb 21 at 23:11
  • as I remember you can use signal.signal(signal.SIGINT, signal_handler) (in python script) to handle Ctrl+C but try/except can be simpler. signals - Python: Catch Ctrl-C command. Prompt "really want to quit (y/n)", resume execution if no - Stack Overflow
    – furas
    Commented Feb 22 at 1:59
  • ^C is just me exiting the program after it does not work, I should have also mentioned that it only gives my trouble when i try to pipe it to another program
    – usr_40476
    Commented Feb 22 at 17:06
  • You can't have a broken pipe if you're not piping. It happens when the program you're piping to exits.
    – Barmar
    Commented Feb 23 at 22:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.