Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.

eddiewalker posted:

You probably commented it out in /etc/modprobe.d/alsa-base.conf or have something amiss in /etc/asound.rc

I got mine to work with no asound.rc at all, so you can just rename that to like asound.rc.old and reboot to see if it's the problem. All I had to do to get a generic USB sound card to work as an input was comment and uncommonly some lines in the default alsa-base.conf

I ended up just doing a fresh install of Raspbian and reinstalled Festival, sphinxbase and pocketsphinx. I changed the index on one line in alsa-base.conf from -2 to 0 so that the USB sound card would be the default card. It now shows as default card, and when I do arecord -l the card shows up as a recording device.

I'm starting to wonder if maybe I just don't have a good microphone hooked up.

Adbot
ADBOT LOVES YOU

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
Sorry for the double post. I got a new microphone and it still doesn't work. I'm starting to think this $0.99 with free shipping USB sound card might not be the best quality

I do have a USB mic that works and captures. Is there a way to set a seperate sound card for the line-in, or to make Pocketsphinx use specifically a certain device?

YouTuber
Jul 31, 2004

by FactsAreUseless

Rubiks Pubes posted:

Sorry for the double post. I got a new microphone and it still doesn't work. I'm starting to think this $0.99 with free shipping USB sound card might not be the best quality

I do have a USB mic that works and captures. Is there a way to set a seperate sound card for the line-in, or to make Pocketsphinx use specifically a certain device?

What? Even those TIGER games at the checkout lanes in the 90s cost more than 99 cent. Can you link the card or give us the name of it?

404notfound
Mar 5, 2006

stop staring at me

Google made an image designed for developing web apps: Coder

TVarmy
Sep 11, 2011

like food and water, my posting has no intrinsic value

It looks pretty nice for teaching kids web development, but I wish it supported the server-side coding as well.

SYSV Fanfic
Sep 9, 2003

by Pragmatica

Brady posted:

Just installed Raspbian via NOOBS and for some reason the GUI takes up more room than the visible screen, ie: my icons and "taskbar" are mostly out of view. I was able to check the display settings and it's showing 1080x1920 with no other options other than "Auto", which sets it to 1080x1920 anyway.

I'm outputting via HDMI to my TV (yes, it's 1080p).

Any ideas?

Assuming the resolution isn't backwords, look at the overscan settings in raspi-config

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
I finally got Pocketsphinx to work by plugging in a USB mic and specifying -plughw:1,0 option from the command line. But the accuracy is total poo poo. One of the sites I saw said to use a 48000 sample rate but every time I try to specify sample rate I get an error message.

eddiewalker
Apr 28, 2004

Arrrr ye landlubber
I never had any luck getting alsa to force my interface to anything but its native sample rate, then I resample down in my recording app just to lower the amount of data to be processed so the RPi doesn't choke.

I don't know anything about the software you're using, but 48k is high, above CD quality even. Telephony is traditionally 8k, so I'd be surprised if the software needed more than that to get intelligible speech.

TVarmy
Sep 11, 2011

like food and water, my posting has no intrinsic value

Anyone talked about this yet?

Tessel appears to be something like a Raspberry Pi or Arduino that runs javascript, apparently in the Node.js style, considering it has NPM (node package manager) support.

It's more a microcontroller than microcomputer, but for people like me, who like the Raspberry Pi because it makes it easy to put GPIO on a network, this looks really cool.

It has built in Wifi, too.

Zuph
Jul 24, 2003
Zupht0r 6000 Turbo Type-R

TVarmy posted:

Anyone talked about this yet?

Tessel appears to be something like a Raspberry Pi or Arduino that runs javascript, apparently in the Node.js style, considering it has NPM (node package manager) support.

It's more a microcontroller than microcomputer, but for people like me, who like the Raspberry Pi because it makes it easy to put GPIO on a network, this looks really cool.

It has built in Wifi, too.

It's a lot closer to an Arduino than a Raspberry Pi, with a Cortex-M3 processor.

I'm interested, but only insofar as they've been able to cram a JavaScript engine on a Cortex-M3.

Powered Descent
Jul 13, 2008

We haven't had that spirit here since 1969.

While we're on the topic of "kinda like a Pi", somehow I managed not to hear about the BeagleBone Black until yesterday. It's five ten bucks more than a Pi and its graphics aren't as nice, but it has a much faster cpu, 2 gigs of onboard storage, and way more I/O connections. I haven't had a chance to play with one yet but it sounds pretty cool.

A comparison: http://makezine.com/magazine/how-to-choose-the-right-platform-raspberry-pi-or-beaglebone-black/

e: Oops, wrong price

Powered Descent fucked around with this message at 18:05 on Sep 22, 2013

hazzlebarth
May 13, 2013

Powered Descent posted:

While we're on the topic of "kinda like a Pi", somehow I managed not to hear about the BeagleBone Black until yesterday. It's five ten bucks more than a Pi and its graphics aren't as nice, but it has a much faster cpu, 2 gigs of onboard storage, and way more I/O connections.

The one thing that makes it even better for non-graphical applications and development work is that you can use the Ubuntu/Debian armhf architecture on the BBB, whereas on the RPI you are stuck with either the Raspbian-armhf rebuild of Debian's wheezy or using Debian armel which is quite slower than armhf.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
I hate to keep posting and asking scripting questions but I am finally, so close to having this setup working the way I want it to.

I am now to the point that I have my little JARVIS rig listening for voice commands using Google's speech to text and turning lights on and off, etc. The only problem is that it is constantly 'cycling' and sending results of nothing to Google. So you have to wait on it if it's in the middle of sending out whatever it's recorded.

Here's the code I have for that part, which works:

code:
#!/bin/bash
clear

talker ()
{
echo "                    Welcome to J.A.R.V.I.S. v1.1"
echo "                                Options"
echo "                     LightsOn, LightsOff, Weather"
echo "====================================================================="
echo "Enter your command"
aplay awaiting.wav -q;
read WHATYOUTYPED

temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
cond=$(cat conditions.txt | sed 's/ //g')

case $WHATYOUTYPED  in
LightsOn)
aplay mypleasure.wav -q;
wemo switch "Living room lights" on;
;;

LightsOff)
aplay mypleasure.wav -q;
wemo switch "Living room lights" off;
;;

Weather)
aplay mypleasure.wav -q;
#echo "/home/pi/jarvissounds/Weather/$cond.wav";
aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
esac

shred -u whatyoutyped; clear
}

while true
do 
talker
done

exit
Now, I read online where someone was using SOX to start and stop the listening. I tried to adapt this code to my code but I keep getting syntax errors and I'm not sure what I'm doing wrong.

Here's the code for what I have:

code:
#!/bin/bash
clear

talker ()
{
echo "                    Welcome to J.A.R.V.I.S. v1.1"
echo "                                Options"
echo "                     LightsOn, LightsOff, Weather"
echo "====================================================================="
echo "Speak your command"
#aplay awaiting.wav -q;
#read WHATYOUTYPED

sox -t alsa plughw:1,0 test.wav silence 1 0 0.5% -1 1.0 1% &

arecord -D plughw:1,0 -f cd -t wav -d 5  -r 16000 | flac - -f --best --sample-rate 16000 -o out.flac; wget -O - -o /dev/null --post-file out.flac --header="Content-Type: audio/x-flac; rate=16000" [url]http://www.google.com/speech-api/v1/recognize?lang=en[/url] | sed -e 's/[{}]/''/g'| awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]; exit }' | awk -F: 'NR==3 { print $3; exit }' > speech.txt
WHATYOUTYPED=$(sed s/\"//g speech.txt)

temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
cond=$(cat conditions.txt | sed 's/ //g')

case $WHATYOUTYPED  in
"lights on")
aplay mypleasure.wav -q;
wemo switch "Living room lights" on;
;;

"lights off")
aplay mypleasure.wav -q;
wemo switch "Living room lights" off;
;;

"weather")
aplay mypleasure.wav -q;
#echo "/home/pi/jarvissounds/Weather/$cond.wav";
aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
esac

shred -u whatyoutyped; clear
}

while true
do
talker
done

exit
Anyone done anything similar and able to help me out?

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

I hate to keep posting and asking scripting questions but I am finally, so close to having this setup working the way I want it to.

I am now to the point that I have my little JARVIS rig listening for voice commands using Google's speech to text and turning lights on and off, etc. The only problem is that it is constantly 'cycling' and sending results of nothing to Google. So you have to wait on it if it's in the middle of sending out whatever it's recorded.

Now, I read online where someone was using SOX to start and stop the listening. I tried to adapt this code to my code but I keep getting syntax errors and I'm not sure what I'm doing wrong.

Here's the code for what I have:

code:
Doing this in bash. :aaaaa:

There's no reason to use "shred -u" over "rm" for what you're doing other than causing extra wear on the SDcard. I also don't see a file named "whatyoutyped" being created at all.

What's missing? Is there a cronjob dumping the weather into weather.txt?

What's your syntax error? It's really hard to help without it.

code:
sox -t alsa plughw:1,0 test.wav silence 1 0 0.5% -1 1.0 1% &

arecord -D plughw:1,0 -f cd -t wav -d 5  -r 16000 | flac - -f --best --sample-rate 16000 -o out.flac; \
wget -O - -o /dev/null --post-file out.flac --header="Content-Type: audio/x-flac; rate=16000" [url]http://www.google.com/speech-api/v1/recognize?lang=en[/url] | sed -e 's/[{}]/''/g'| \ 
awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]; exit }' | awk -F: 'NR==3 { print $3; exit }' > speech.txt
Please don't do this. For multiple reasons. You probably want Sox to listen to at least half a second (which is a very reasonable length for voice commands) before it starts recording.

Don't background it. Don't "arecord" into flac (sox will do this by itself). It presumably blocks (nothing else in your script executes while it's waiting). That's what you want. Everything else after it is contingent on recognizing what's in that wav, so there's no point in continuing if it hears nothing (other than potentially getting blackholed for abuse of Google's servers). Don't use wget for POSTs, use curl (libcurl is a million times more capable and you should be using curl for everything you'd use wget for anyway). Additionally, by the time you're using multiple awks in a very lone pipeline, it's time to consider another language. Or assigning the results to variables (that you can then echo into awk for more processing). There's a lot that can go wrong in your pipeline.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
I've never programmed anything before. This is a mishmash of other projects I've found online and hacked together to accomplish this. A cronjob dumps the weather data hourly into weather.txt.

I will post the syntax error when I get home. It appears to be a missing single quote but I can't find it.

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

I've never programmed anything before. This is a mishmash of other projects I've found online and hacked together to accomplish this. A cronjob dumps the weather data hourly into weather.txt.

I will post the syntax error when I get home. It appears to be a missing single quote but I can't find it.

code:
sed -e 's/[{}]/''/g'
You need to escape the apostrophes in the middle if you actually want to use that. You'd be better off using "" or some other kind of quotes instead.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
OK, I got it to run using the following code but it doesn't seem to send anything to Google for translation. I don't get any feedback from anything spoken into the mic.
But, it runs!

code:
#!/bin/bash
clear

talker ()
{
echo "                    Welcome to J.A.R.V.I.S. v3.0 Beta"
echo "                                Options"
echo "                     LightsOn, LightsOff, Weather"
echo "====================================================================="
echo "Speak your command"
#aplay awaiting.wav -q;
#read WHATYOUTYPED

#mplayer -ao plughw:1,0 -really-quiet -http-header-fields "User-Agent:Mozilla/5.0 (Windows #NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari #537.22m" 
#"http://translate.google.com/translate_tts?tl=en7q=$1";

sox -t alsa plughw:1,0 test.wav silence 1 0 0.5% -1 1.0 1% &
sox_pid=$!

ffmpeg -loglevel panic -y -i test.wav -ar 16000 -acodec flac file.flac
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-en&client=chromium" | cut -d\" -f12 >speech.txt

WHATYOUTYPED=$(sed s/\"//g speech.txt)

temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
cond=$(cat conditions.txt | sed 's/ //g')


case $WHATYOUTYPED  in
"lights on")
aplay mypleasure.wav -q;
wemo switch "Living room lights" on;
;;

"lights off")
aplay mypleasure.wav -q;
wemo switch "Living room lights" off;
;;

"weather")
aplay mypleasure.wav -q;
#echo "/home/pi/jarvissounds/Weather/$cond.wav";
aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
esac

rm whatyoutyped; clear
}

while true
do
talker
done

exit

evol262
Nov 30, 2010
#!/usr/bin/perl
Stop and think about this.

code:
do_something() {
sox -t alsa plughw:1,0 test.wav silence 1 0 0.5% -1 1.0 1% &
sox_pid=$!

ffmpeg -loglevel panic -y -i test.wav -ar 16000 -acodec flac file.flac
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-en&client=chromium" | cut -d\" -f12 >speech.txt

WHATYOUTYPED=$(sed s/\"//g speech.txt)
}

while true
  dosomething
done
What are you actually doing here? Take a step back and think.

So you start sox. You background it so it keeps running. You keep track of the PID (which you do absolutely nothing with)

You immediately try to reencode as flac. Why? Does Google require flac? Why not have sox do this itself?
The problem with this is that you're not checking whether or not the sox pid has exited. You're not even checking if the .wav you're trying to convert exists.
Then you try to POST that flac to read it. And parse it with sed. Why are you escaping the quote here?
You immediately hit talker() again, with the previous instance of sox potentially running. I have no idea what happens if you try to start a second instance listening on the same device. Does it start? Does it crash?
You try to convert a test.wav that still may not exist.

Here are the problems with your script:

The Pi's CPU is weak. Converting between wav and flac isn't a great idea when sox can do flac directly.
You're not checking whether or not test.wav even exists before you try to convert it (and there are extremely good odds that it will not)
You're not checking whether or not test.wav has been written to in the last second -- in other words, whether or not sox is still trying to record a command, and there are extremely good odds that it will be.
You're still hammering Google's servers with useless garbage.
You don't do anything with the PID.

What you script needs to do:
Not background sox or check to see whether sox_pid is still running or stat() test.wav and check the times. This solves all the other problems. Checking whether the PID is still running will uselessly hammer the (weak) CPU. Just let sox do its thing and go from there. As I said in my last post, your entire script depends on that output. Wait for it.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.

evol262 posted:


You keep track of the PID (which you do absolutely nothing with)

The script I used as my base did some monitoring to close the sox PID if there was silence, but I couldn't get my script to work properly with that part in there.

quote:

You immediately try to reencode as flac. Why? Does Google require flac? Why not have sox do this itself?

EDIT: Google does require FLAC

quote:

The problem with this is that you're not checking whether or not the sox pid has exited. You're not even checking if the .wav you're trying to convert exists.

How would I go about doing either of these things?

quote:

Then you try to POST that flac to read it. And parse it with sed. Why are you escaping the quote here?

The script looks for the output from Google for each case. Google returns it in quotes. So I need to remove the quotes for it to work as a case.

quote:

You immediately hit talker() again, with the previous instance of sox potentially running. I have no idea what happens if you try to start a second instance listening on the same device. Does it start? Does it crash?

I do get an error message on occasion that the resource for recording is unavailable. I assume that's because of this.

quote:

You try to convert a test.wav that still may not exist.

Again, I'm flying by the seat of my pants here so what do I need to do to check that it's there?

quote:

What you script needs to do:
Not background sox or check to see whether sox_pid is still running or stat() test.wav and check the times. This solves all the other problems. Checking whether the PID is still running will uselessly hammer the (weak) CPU. Just let sox do its thing and go from there. As I said in my last post, your entire script depends on that output. Wait for it.

What exactly is causing it to run backgrounded in the options?

How would I check to see if it is still running?

And how do I check the times?

I 100% appreciate the fact that you are helping me out here... and I hope I'm not being too annoying. But I am beyond a newbie at this and am pretty much doing this through trial and error and Googling.

edit: I looked up how to check if the file exists and added an if/then to the script to make sure it's not doing anything with the file if it isn't there.

Also I added in the code from the other script that kills the SOX PID if necessary. When I try to run it I get a syntax error on line 91 which is the last } in the file - I am assuming that something I added is the cause of it.

The error is:
./jarvis4.sh: line 91: syntax error near unexpected token `}'
./jarvis4.sh: line 91: `}'


code:
#!/bin/bash
clear

talker ()
{
echo "                    Welcome to J.A.R.V.I.S. v4.0 Beta"
echo "                                Options"
echo "                     LightsOn, LightsOff, Weather"
echo "====================================================================="
echo "Speak your command"
#aplay awaiting.wav -q;
#read WHATYOUTYPED

#mplayer -ao plughw:1,0 -really-quiet -http-header-fields "User-Agent:Mozilla/5.0 (Windows #NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari #537.22m" 
#"http://translate.google.com/translate_tts?tl=en7q=$1";

sox -t alsa plughw:1,0 file.flac silence 1 0 0.5% -1 1.0 1% &
sox_pid=$!

while [ $count -le 9 ]
do
   
size=$(stat --printf="%s" file.flac)

if [ $size -gt $lastsize ]
	then
		if [ $first -eq 0 ]
		then
			echo "Recording!"
			rec=1
		else
			first=0
		fi
	else
		if [ $rec -eq 1 ]
			then
				echo "Silence"
				kill $sox_pid

#ffmpeg -loglevel panic -y -i test.wav -ar 16000 -acodec flac file.flac

FILE=$1

if [ -f file.flac ];
	then
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-en&client=chromium" | cut -d\" -f12 >speech.txt

	else
		echo "File $FILE does not exist"
	fi

WHATYOUTYPED=$(sed s/\"//g speech.txt)

temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
cond=$(cat conditions.txt | sed 's/ //g')


case $WHATYOUTYPED  in
"lights on")
aplay mypleasure.wav -q;
wemo switch "Living room lights" on;
;;

"lights off")
aplay mypleasure.wav -q;
wemo switch "Living room lights" off;
;;

"bedroom light on")
aplay mypleasure.wav -q;
wemo switch "bedroom" on;
;;

"bedroom light off")
aplay mypleasure.wav -q;
wemo switch "bedroom" off;
;;

"weather")
aplay mypleasure.wav -q;
#echo "/home/pi/jarvissounds/Weather/$cond.wav";
aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
esac

rm whatyoutyped; clear
}

while true
do
talker
done

exit
And again most of what I added with regards to handling the SOX PID and echoing silence/recording came from the original script I found. So if it's screwy that may be why.

Rubiks Pubes fucked around with this message at 01:29 on Sep 27, 2013

Fly
Nov 3, 2002

moral compass
Sox is running the background because you have an ampersand after the command.

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

Also I added in the code from the other script that kills the SOX PID if necessary. When I try to run it I get a syntax error on line 91 which is the last } in the file - I am assuming that something I added is the cause of it.
You're missing two "fi"s.

But that's ok. Let's step back a bit. What do you want the script to do?

Listen on the mic.
How does it do that?
It starts sox and starts recording when it hears something.

Ok, so how do you know when sox is done?
You can pick from these choices:
  • Check to see whether sox is done writing the output file (the stat method)
  • Check whether or not sox is still running (we're assuming that if sox isn't running, it's done recording and exited
  • Block -- this means "wait for the previous step and don't do anything else

The ampersand says "detach this from the foreground and run as a background job in the current shell". "nohup" would detach from the current shell and run on its own (effectively setting the parent PID (PPID in ps) to 1, so it doesn't get reaped when the parent process goes away).

Removing the ampersand will make sox block. Sox won't proceed to the next command until it exits (and it won't exit until it's done recording). This immediately removes all of your problems. I mean, there's a possibility that it'll write some gibberish. Or you'll accidentally kill it. Or whatever. But your script basically stops here and waits for input, which exactly matches the behaviour of your "read" in the original script.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
Awesome! Thank you for putting it in simple terms for me. That totally makes sense. I will add the "fi"s in and get rid of the ampersand and see how that goes.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
OK I removed the ampersand and added in the missing "fi" and I am still getting the same drat syntax error. I can't figure it out.

Is there a better program I can use to edit than TextEdit on OSX? I used to use Coda for web editing and I liked the color coding.

Anyway here is the current code and syntax error:

code:
#!/bin/bash
clear

talker ()
{
echo "                    Welcome to J.A.R.V.I.S. v4.0 Beta"
echo "                                Options"
echo "                     LightsOn, LightsOff, Weather"
echo "====================================================================="
echo "Speak your command"
#aplay awaiting.wav -q;
#read WHATYOUTYPED

#mplayer -ao plughw:1,0 -really-quiet -http-header-fields "User-Agent:Mozilla/5.0 (Windows #NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari #537.22m" 
#"http://translate.google.com/translate_tts?tl=en7q=$1";

sox -t alsa plughw:1,0 file.flac silence 1 0 0.5% -1 1.0 1% 
sox_pid=$!

while [ $count -le 9 ]
do
   
size=$(stat --printf="%s" file.flac)

if [ $size -gt $lastsize ]
	then
		if [ $first -eq 0 ]
		then
			echo "Recording!"
			rec=1
		else
			first=0
		fi
	else
		if [ $rec -eq 1 ]
			then
				echo "Silence"
				kill $sox_pid
		fi

#ffmpeg -loglevel panic -y -i test.wav -ar 16000 -acodec flac file.flac

FILE=$1

if [ -f file.flac ];
	then
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-en&client=chromium" | cut -d\" -f12 >speech.txt

	else
		echo "File $FILE does not exist"
	fi

WHATYOUTYPED=$(sed s/\"//g speech.txt)

temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
cond=$(cat conditions.txt | sed 's/ //g')


case $WHATYOUTYPED  in
"lights on")
aplay mypleasure.wav -q;
wemo switch "Living room lights" on;
;;

"lights off")
aplay mypleasure.wav -q;
wemo switch "Living room lights" off;
;;

"bedroom light on")
aplay mypleasure.wav -q;
wemo switch "bedroom" on;
;;

"bedroom light off")
aplay mypleasure.wav -q;
wemo switch "bedroom" off;
;;

"weather")
aplay mypleasure.wav -q;
#echo "/home/pi/jarvissounds/Weather/$cond.wav";
aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
esac

rm whatyoutyped; clear
}

while true
do
talker
done

exit
jarvis4.sh: line 92: syntax error near unexpected token `}'
jarvis4.sh: line 92: `}'

WTF am i missing?

Guy Axlerod
Dec 29, 2008
Your first if doesn't have a matching fi.

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

OK I removed the ampersand and added in the missing "fi" and I am still getting the same drat syntax error. I can't figure it out.
You don't actually need any of the other checks as long as sox is blocking, just FYI.

Rubiks Pubes posted:

Is there a better program I can use to edit than TextEdit on OSX? I used to use Coda for web editing and I liked the color coding.
vim, but that's an entirely different argument. The best thing you can do for yourself in order to spot this is to format the text properly, with indentation that matches up for when you enter/exit levels (if/while/etc).

Rubiks Pubes posted:

Anyway here is the current code and syntax error:

code:
#!/bin/bash
clear

talker ()
{
echo "                    Welcome to J.A.R.V.I.S. v4.0 Beta"
echo "                                Options"
echo "                     LightsOn, LightsOff, Weather"
echo "====================================================================="
echo "Speak your command"

sox -t alsa plughw:1,0 file.flac silence 1 0 0.5% -1 1.0 1% 
sox_pid=$!

while [ $count -le 9 ]
do
   
  size=$(stat --printf="%s" file.flac)

  if [ $size -gt $lastsize ]
  then
    if [ $first -eq 0 ]
    then
	echo "Recording!"
	rec=1
    else
	first=0
    fi
    #Is this what you wanted to do?
    else
      if [ $rec -eq 1 ]
      then
	echo "Silence"
	kill $sox_pid
      fi
  #fi

  FILE=$1

  if [ -f file.flac ];
  then
    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-en&client=chromium" | cut -d\" -f12 >speech.txt

  else
    echo "File $FILE does not exist"
  fi

  WHATYOUTYPED=$(sed s/\"//g speech.txt)

  temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
  cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
  cond=$(cat conditions.txt | sed 's/ //g')


  case $WHATYOUTYPED  in
    "lights on")
      aplay mypleasure.wav -q;
      wemo switch "Living room lights" on;
    ;;

    "lights off")
      aplay mypleasure.wav -q;
      wemo switch "Living room lights" off;
    ;;

    "bedroom light on")
      aplay mypleasure.wav -q;
      wemo switch "bedroom" on;
    ;;

    "bedroom light off")
      aplay mypleasure.wav -q;
      wemo switch "bedroom" off;
    ;;

    "weather")
      aplay mypleasure.wav -q;
      aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
      aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
      aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
      aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
      aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
  esac

  rm whatyoutyped; clear
}

while true
do
  talker
done

exit
Spot the errors now.

Boz0r
Sep 7, 2006
The Rocketship in action.
I'm looking to use my Pi as a gaming console for NES/SNES games. I tried downloading a RetroPi image but I can't figure out how to get it to work properly. I try following a couple of guides, but it always boots into some Apple OS and I don't really know how to start the actual emulator.

How do I do this when I'm incredibly lazy?

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.

evol262 posted:

You don't actually need any of the other checks as long as sox is blocking, just FYI.

vim, but that's an entirely different argument. The best thing you can do for yourself in order to spot this is to format the text properly, with indentation that matches up for when you enter/exit levels (if/while/etc).

Spot the errors now.

OK, so I copied and pasted exactly what was in this box and replaced what I had. I uncommented the one #fi (which I assume was the one missing) and tried running it and am still getting the same error, this time on line 87.

Not sure what to do about your comment on killing the SOX pid. I tried completely commenting out that section and it still gave the same syntax error. I cannot figure out what I am missing now.

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

OK, so I copied and pasted exactly what was in this box and replaced what I had. I uncommented the one #fi (which I assume was the one missing) and tried running it and am still getting the same error, this time on line 87.

Not sure what to do about your comment on killing the SOX pid. I tried completely commenting out that section and it still gave the same syntax error. I cannot figure out what I am missing now.
See the comments.
code:
#!/bin/bash
clear

talker ()
{
  echo "                    Welcome to J.A.R.V.I.S. v4.0 Beta"
  echo "                                Options"
  echo "                     LightsOn, LightsOff, Weather"
  echo "====================================================================="
  echo "Speak your command"
  
  sox -t alsa plughw:1,0 file.flac silence 1 0 0.5% -1 1.0 1% 
  sox_pid=$!

  # Don't need this at all, and you were missing the "done" 
  #while [ $count -le 9 ]
  #do 
     
    size=$(stat --printf="%s" file.flac)
 
    # $(( 1 + 1 )) -- bash syntax for math
    # We're comparing the date in seconds to the time in seconds to see if 
    # one second has elapsed
    # But we don't need ANY of this, because you won't get here until sox
    # exits
    if [ "$(( $(date +"%s") - $(stat -c "%Y" file.flac) ))" -gt "1" ]
    then
      echo "Recording!"
      rec=1
    else
      # If you wanted to continue this line of reasoning
      # you'd kill sox, break out of your loop, and 
      # restart, so let's do that
      kill -9 $sox_pid
      break
    fi
 
    # You don't have any command line arguments. What you you doing here? 
    FILE=$1
  
    if [ -f file.flac ]
    then
      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-en&client=chromium" | cut -d\" -f12 >speech.txt
 
    else
      # Not the error you want. You're not doing anything at all with $FILE
      echo "File $FILE does not exist"
    fi
  
    WHATYOUTYPED=$(sed s/\"//g speech.txt)
  
    temp=$(awk '/Temperature/ {print $2}' weather.txt | awk '{printf("%.0f\n", $1)}')
    cat weather.txt | grep "Sky conditions: " | sed 's/Sky conditions: //' > conditions.txt
    cond=$(cat conditions.txt | sed 's/ //g')
  
  
    case $WHATYOUTYPED  in
      "lights on")
        aplay mypleasure.wav -q;
        wemo switch "Living room lights" on;
      ;;
  
      "lights off")
        aplay mypleasure.wav -q;
        wemo switch "Living room lights" off;
      ;;
  
      "bedroom light on")
        aplay mypleasure.wav -q;
        wemo switch "bedroom" on;
      ;;
  
      "bedroom light off")
        aplay mypleasure.wav -q;
        wemo switch "bedroom" off;
      ;;
  
      "weather")
        aplay mypleasure.wav -q;
        aplay /home/pi/jarvissounds/Weather/$cond.wav -q;
        aplay /home/pi/jarvissounds/Weather/thetemperatureis.wav -q;
        aplay /home/pi/jarvissounds/Numbers/$temp.wav -q;
        aplay /home/pi/jarvissounds/Weather/degrees.wav -q;
        aplay /home/pi/jarvissounds/Weather/fahrenheit.wav -q;
    esac
  
    rm whatyoutyped
    clear
}

while true
do
  talker
done

exit

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
OK, now it runs, and records, but it doesn't stop recording. It doesn't do anything with any of the commands listed in the script. If I hit enter on the keyboard it just starts recording again.

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

OK, now it runs, and records, but it doesn't stop recording. It doesn't do anything with any of the commands listed in the script. If I hit enter on the keyboard it just starts recording again.

This is sort of beyond what a forum can do. Is speech.txt there? What's in it?

Start echoing out your variables to see what's happening.

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.

evol262 posted:

This is sort of beyond what a forum can do. Is speech.txt there? What's in it?

Start echoing out your variables to see what's happening.

speech.txt is there but there's nothing in it. When I play back file.flac it's just static.

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

speech.txt is there but there's nothing in it. When I play back file.flac it's just static.

Mic broken? Bad sox options?

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
The mic worked with the old script so I doubt it's broken. Not sure about sox options. I'll fiddle with it. I appreciate your help but I don't want to continue flooding this thread with this crap.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

You could post a thread in the programming forum, I'm sure people will be into it

e- I have no idea what I'm talking about here, but if you're getting non-stop recording and it's static, you probably want to take a close look at the sox options and make real sure it's using the right audio source with all the trimmings. If you're just reading in a ton of noise from somewhere your silence-detection stuff is never going to trip and end the show.

edit again: I'd specifically look at this
http://wiki.audacityteam.org/wiki/USB_mic_on_Linux#Making_sure_ALSA_detects_the_mic
make sure that plughw:1,0 (which refers to Card 1, Device 0 in the lists you get) is definitely referring to your mic

baka kaba fucked around with this message at 01:25 on Sep 29, 2013

evol262
Nov 30, 2010
#!/usr/bin/perl

Rubiks Pubes posted:

The mic worked with the old script so I doubt it's broken. Not sure about sox options. I'll fiddle with it. I appreciate your help but I don't want to continue flooding this thread with this crap.

Suggestion: test sox just on its own with the same options.

DoctorOozy
Jun 22, 2013

Like you get in packing paper?

Boz0r posted:

I'm looking to use my Pi as a gaming console for NES/SNES games. I tried downloading a RetroPi image but I can't figure out how to get it to work properly. I try following a couple of guides, but it always boots into some Apple OS and I don't really know how to start the actual emulator.

How do I do this when I'm incredibly lazy?

I spent an afternoon playing with RetroPi. You have to select the type of emulation you want, there was some key to open the menu or switch between emulations. Try mashing the keyboard a bit.

I did not play with it for long because I could not work out how to get a controller working so gave it up as being a bit too underdeveloped for my low level skills to manage. I intend to return later when there was a bit more support available. I did get Street fighter 2 turbo running from the keyboard though and it worked well.

SYSV Fanfic
Sep 9, 2003

by Pragmatica
This thread is too quiet. Anyone doing anything cool with their PI? I am making a kit for deaf people that converts their standard doorbell into a doorbell that sends a text when it is pressed. It uses an AC optocoupler and the python software just polls a gpio pin. The rest is just sending a http request to an sms gateway via mechanize.

I wish the pi would catch on in the states outside of hackerspaces... I also think the raspberry pi foundation should shell out a little bit of money to be able to include dive into python on the raspbian image. For kids that don't know anything, without internet access, etc. A big link on the desktop that said "GET STARTED HERE ->". It would also be pretty cool if someone funded a MECC type company for the raspberry pi. I've already said it, but the pi has all the computing power necessary to replace PCs in elementary schools. I have fond memories of my elementary school lab full of apple IIs in 1992. The benefit of the PI would be that the kids could easily have one at home and all they would need to do would be take the SD card with them. I guess all the educational buzz in the US is around tablets though.

SYSV Fanfic fucked around with this message at 18:59 on Oct 2, 2013

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

keyvin posted:

This thread is too quiet. Anyone doing anything cool with their PI? I am making a kit for deaf people that convert their standard doorbell into a doorbell that sends a text when it is pressed. It uses an AC optocoupler and the python software just polls a gpio pin. The rest is just sending a http request to an sms gateway via mechanize.

I was making something using the gPhoto2 libraries to make the Pi send a liveview from my DSLR to my phone via Bluetooth. I got the Pi talking to my camera, but then before I could fully figure out Bluetooth, my phone's Bluetooth seems to have died and doesn't work for any kind of file transfer now.

DoctorOozy
Jun 22, 2013

Like you get in packing paper?

keyvin posted:

This thread is too quiet. Anyone doing anything cool with their PI?

I just completed a servo-wheeled robot controlled by a wireless pi mounted on it. Playing with python now to try to make an interface on my phone to control it. I am also looking into peoples quad-copter projects but thinking its probably a little beyond me right now.

Adbot
ADBOT LOVES YOU

Rubiks Pubes
Dec 5, 2003

I wanted to be a neo deconstructivist, but Mom wouldn't let me.
Well my project is pretty much stuck. I'm thinking about finding something else to do with mine but I'm not sure what.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply