summaryrefslogtreecommitdiff
path: root/client/speaker.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-06-08 20:39:35 -0700
committerschneefux <schneefux+commit@schneefux.xyz>2014-06-21 12:39:11 -0700
commit84a92e5327997815488276021e5498f7681ab2d7 (patch)
tree972b154650d9a4ae3bd0a77b1ace36d403457053 /client/speaker.py
parent1744368ac1889fe0767f04d55e8f928553c8db1c (diff)
downloadjasper-client-84a92e5327997815488276021e5498f7681ab2d7.tar.gz
jasper-client-84a92e5327997815488276021e5498f7681ab2d7.zip
Stop hardcoding /home/jasper and abstract out mic.say for multiplatform support
Diffstat (limited to 'client/speaker.py')
-rw-r--r--client/speaker.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/client/speaker.py b/client/speaker.py
new file mode 100644
index 0000000..304b426
--- /dev/null
+++ b/client/speaker.py
@@ -0,0 +1,35 @@
+"""
+A Speaker handles output from Jasper to the user.
+"""
+import os, json
+
+class PiSpeaker:
+
+ @classmethod
+ def isAvailable(cls):
+ 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.playSound("say.wav")
+
+ def playSound(self, filename):
+ os.system("aplay -D hw:1,0 " + filename)
+
+class MacSpeaker:
+
+ @classmethod
+ def isAvailable(cls):
+ return os.system("which say") == 0
+
+ def say(self, phrase):
+ os.system("say " + phrase)
+
+ def playSound(self, filename):
+ os.system("afplay " + filename)
+
+def newSpeaker():
+ for cls in [PiSpeaker, MacSpeaker]:
+ if cls.isAvailable():
+ return cls()
+ raise ValueError("Platform is not supported")