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 --- events.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'events.py') 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]]) -- cgit v1.2.3