From a40620d2acdd78fb6923d21ca816f16fd15a6331 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 15 Aug 2021 17:29:06 +0100 Subject: Add tts engine selector, and email recordings --- dial.py | 2 +- events.py | 34 +++++++++++++++++++++++++++------- main.py | 1 - 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/dial.py b/dial.py index fa5ca9e..215680a 100644 --- a/dial.py +++ b/dial.py @@ -55,7 +55,6 @@ class DialManager: self.phone = phone self.update = datetime.now() self._load_sequences() - print(self.sequences) def _load_sequences(self): def recursive_add(classname, sequence_list, sequences, args): @@ -71,6 +70,7 @@ class DialManager: parts = config["sequences"][sequence].split(" ", 1) classname = parts[0] args = parts[1:] + print(sequence, classname, args, sep="\t") recursive_add(classname, list(sequence), self.sequences, args) def dial(self, number): diff --git a/events.py b/events.py index 36ca972..ce21ad9 100644 --- a/events.py +++ b/events.py @@ -1,8 +1,13 @@ import subprocess +import requests +import smtplib + +from config import config +from email.message import EmailMessage from datetime import datetime from config import config -import requests from multiprocessing import Process +from os.path import basename def tts_command(text): if config["engine"]["tts"] == "espeak": @@ -101,23 +106,38 @@ class RecordEvent(Event): def run(self): self.phone.run_until_hangup(tts_command("Please record a message.")) - - process = subprocess.Popen(["arecord", "/tmp/out.wav"]) + process = subprocess.Popen(["arecord", config["engine"]["filename"]]) self.phone.wait_until_hung_up() process.terminate() - return "recording done" - + self._send_recording() + return "" + + def _send_recording(self): + msg = EmailMessage() + msg["Subject"] = "Phone Recording" + msg["From"] = config["email"]["user"] + msg["To"] = config["email"]["user"] + msg.set_content("Attached is your message.") + with open(config["engine"]["filename"], 'rb') as f: + data = f.read() + msg.add_attachment(data, maintype="audio", subtype="wav", filename="recording.wav") + + s = smtplib.SMTP(config["email"]["server"], int(config["email"]["port"])) + s.starttls() + s.login(config["email"]["user"], config["email"]["pass"]) + s.send_message(msg) + s.quit() class PlayEvent(Event): def get_name(self): return "play" def run(self): - self.phone.run_until_hangup(["aplay", "/tmp/out.wav"]) + self.phone.run_until_hangup(["aplay", config["engine"]["filename"]]) class WavEvent(Event): def get_name(self): - return self.args[0] + return basename(self.args[0]) def run(self): self.phone.run_until_hangup(["aplay", self.args[0]]) diff --git a/main.py b/main.py index 7c41d7b..5485c9c 100755 --- a/main.py +++ b/main.py @@ -13,6 +13,5 @@ if __name__ == "__main__": phone.process_dial() except Exception as e: print(e) - raise e finally: phone.clear_event() -- cgit v1.2.3