From c1783980db7a20ea86bfb009a410469f3dc8d5d2 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Mon, 28 Sep 2015 22:44:01 +0200 Subject: Mock phone: gets numbers and reads them aloud. --- callers/read_numbers_aloud.py | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 callers/read_numbers_aloud.py (limited to 'callers/read_numbers_aloud.py') 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() -- cgit v1.2.3