summaryrefslogtreecommitdiff
path: root/callers/read_numbers_aloud.py
diff options
context:
space:
mode:
Diffstat (limited to 'callers/read_numbers_aloud.py')
-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()