6

i am working on speech recognition . for this i am using "alsa-utils" but when i try to use this script

    #!/bin/bash

echo “Recording… Press Ctrl+C to Stop.”
arecord -D plughw:1,0 -q -f cd -t wav | ffmpeg -loglevel panic -y -i – -ar 16000 -acodec flac file.flac > /dev/null 2>&1

echo “Processing…”
wget -q -U “Mozilla/5.0” –post-file file.flac –header “Content-Type: audio/x-flac; rate=16000” -O – “http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium” | cut -d” -f12 >stt.txt

echo -n “You Said: ”
cat stt.txt

rm file.flac > /dev/null 2>&1

i am getting this error

    “Recording… Press Ctrl+C to Stop.”
ALSA lib pcm_hw.c:1667:(_snd_pcm_hw_open) Invalid value for card
arecord: main:722: audio open error: No such file or directory
“Processing…”

please help :(

Aaditya Ura
  • 12,007
  • 7
  • 50
  • 88

1 Answers1

3

From the pastebin I see card 0 then device 0 or device 1, so try lining up the arecord command with card,device in that order like one of these,

arecord -D plughw:0,0 -q -f cd -t wav | ...
arecord -D plughw:0,1 -q -f cd -t wav | ...
jamieguinan
  • 1,640
  • 1
  • 10
  • 14
  • you are really genius :) ok what i did is i put only first line `arecord -D plughw:0,0 -q -f cd -t wav | ...` and one error gone . now only this error showing `arecord: main:722: audio open error: No such file or directory` so i have two confusion one confusion is should i put both command which you replied in my script or only one ?? i did only one and its working should i add second one too or leave it as it is now. second confusion about `arecord: main:722: audio open error: No such file or directory` – Aaditya Ura Feb 15 '16 at 09:50
  • ok first one is working sir . so i am leaving it as it is but now i am facing only this error :( `arecord: main:722: audio open error: No such file or directory` – Aaditya Ura Feb 15 '16 at 09:54
  • So it no longer says "Invalid value for card", but still says "audio open error: No such file or directory?" – jamieguinan Feb 15 '16 at 09:58
  • Try something like the command in this pastebin (which shows the first few bytes of the wave output generated) until you can get arecord working properly: http://pastebin.com/pwSBFBKw – jamieguinan Feb 15 '16 at 10:05
  • i tried pastebin command and i got this `arecord: main:722: audio open error: Device or resource busy` – Aaditya Ura Feb 15 '16 at 10:08
  • bdw i just removed -D from code and now second error also gone but i am not getting any sound output ? is this google api error or something causes i can see sound output file in folder but can't get response in terminal – Aaditya Ura Feb 15 '16 at 10:10
  • If you remove `-D` it will simply record the default audio device to a file called `plughw:0,0`. What is the output of the command `fuser /dev/snd/pcm*` ? – jamieguinan Feb 15 '16 at 10:19
  • sir should i remove -D or not ?? will it affect my code or i will face any error in future ?? and output of `fuser /dev/snd/pcm*` `exepaul@ubuntu:~$ fuser /dev/snd/pcm* /dev/snd/pcmC0D0c: 25039m` – Aaditya Ura Feb 15 '16 at 10:25
  • Keep the `-D`. And run `ps aux` or `gnome-system-monitor` and look for process 25039, which is holding your device and causing the `Device or resource busy`. – jamieguinan Feb 15 '16 at 10:28
  • sir i got this result of `ps aux' command `exepaul 25039 9.7 2.8 550872 28828 ? S – Aaditya Ura Feb 15 '16 at 10:34
  • Ok, `pulseaudio` is managing your audio device, which it will do if you have a browser open. Try closing any apps that might be producing audio, including your web browser, and `pulseaudio` should release the device so that `arecord` can use it directly. – jamieguinan Feb 16 '16 at 09:00
  • Also try removing the `-D` option _and also the device name_, like this: `arecord -q -f cd -t wav`, which should use arecord through pulseaudio. I don't have much experience with pulseaudio, but this is my best guess. Good luck to you. – jamieguinan Feb 16 '16 at 09:03