summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2015-09-28 22:44:01 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2015-09-28 22:44:01 +0200
commitc1783980db7a20ea86bfb009a410469f3dc8d5d2 (patch)
tree040dfe190f899e71cc18a57bb163e8318e52e882
parentcb4f3500bcacec7cd377a8b0de28799b2bc01972 (diff)
Mock phone: gets numbers and reads them aloud.
-rwxr-xr-xcallers/read_numbers_aloud.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/callers/read_numbers_aloud.py b/callers/read_numbers_aloud.py
new file mode 100755
index 0000000..d74f08d
--- /dev/null
+++ b/callers/read_numbers_aloud.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+
+import asyncio
+import sys
+
+from espeak import espeak
+
+
+class Speaker(object):
+
+ def __init__(self, voice='europe/it'):
+ espeak.set_voice(voice)
+
+ def speak(self, number):
+ print("Calling %s" % number)
+ espeak.synth(number)
+
+
+class Reader(object):
+ """
+ """
+
+ def __init__(self):
+ self.number = ""
+ self.handle = None
+ self.speaker = Speaker()
+
+ def read_number(self):
+ text = sys.stdin.readline()
+ if len(text) == 2 and text[0] in "0123456789":
+ self.number += text[0]
+ if self.handle:
+ self.handle.cancel()
+ self.handle = self.loop.call_later(3, self.call_number)
+ # TODO: do we want a warning in case we receive something wrong?
+
+ def call_number(self):
+ self.speaker.speak(self.number)
+ self.number = ""
+
+ def run(self):
+ self.loop = asyncio.get_event_loop()
+ self.loop.add_reader(sys.stdin, self.read_number)
+ try:
+ self.loop.run_forever()
+ finally:
+ self.loop.close()
+
+
+def main():
+ reader = Reader()
+ reader.run()
+
+if __name__ == '__main__':
+ main()