-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Platform independent audio output. Stop hardcoding /home/jasper. #100
Changes from all commits
8c31973
dd794c2
b9996bf
6217a13
b8b4cc4
cdb08ff
64d54e5
4391496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
cd /home/pi/jasper/boot/ | ||
#!/bin/bash | ||
if [[ -z "$JASPER_HOME" ]]; then | ||
if [[ -d "/home/pi" ]]; then | ||
JASPER_HOME="/home/pi" | ||
export JASPER_HOME; | ||
else | ||
echo "Error: \$JASPER_HOME is not set." | ||
exit 0; | ||
fi | ||
fi | ||
|
||
cd $JASPER_HOME/jasper/boot | ||
LD_LIBRARY_PATH="/usr/local/lib" | ||
export LD_LIBRARY_PATH | ||
PATH=$PATH:/usr/local/lib/ | ||
export PATH | ||
python boot.py & | ||
python boot.py & |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
A Speaker handles audio output from Jasper to the user | ||
Speaker methods: | ||
say - output 'phrase' as speech | ||
play - play the audio in 'filename' | ||
isAvailable - returns True if the platform supports this implementation | ||
""" | ||
import os | ||
import json | ||
|
||
class eSpeakSpeaker: | ||
""" | ||
Uses the eSpeak speech synthesizer included in the Jasper disk image | ||
""" | ||
@classmethod | ||
def isAvailable(cls): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a slight misrepresentation to say that, just because you have eSpeak installed, you're on a Raspberry Pi. I would propose renaming these classes to |
||
return os.system("which espeak") == 0 | ||
|
||
def say(self, phrase, OPTIONS=" -vdefault+m3 -p 40 -s 160 --stdout > say.wav"): | ||
os.system("espeak " + json.dumps(phrase) + OPTIONS) | ||
self.play("say.wav") | ||
|
||
def play(self, filename): | ||
os.system("aplay -D hw:1,0 " + filename) | ||
|
||
class saySpeaker: | ||
""" | ||
Uses the OS X built-in 'say' command | ||
""" | ||
|
||
@classmethod | ||
def isAvailable(cls): | ||
return os.system("which say") == 0 | ||
|
||
def shellquote(self, s): | ||
return "'" + s.replace("'", "'\\''") + "'" | ||
|
||
def say(self, phrase): | ||
os.system("say " + self.shellquote(phrase)) | ||
|
||
def play(self, filename): | ||
os.system("afplay " + filename) | ||
|
||
def newSpeaker(): | ||
""" | ||
Returns: | ||
A speaker implementation available on the current platform | ||
Raises: | ||
ValueError if no speaker implementation is supported on this platform | ||
""" | ||
|
||
for cls in [eSpeakSpeaker, saySpeaker]: | ||
if cls.isAvailable(): | ||
return cls() | ||
raise ValueError("Platform is not supported") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
cd /home/pi/jasper/client/ | ||
cd $JASPER_HOME/jasper/client | ||
rm -rf ../old_client | ||
python main.py & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add docstrings to these classes, and take note of the comment on line 9 as well?