aboutsummaryrefslogtreecommitdiff
path: root/events.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2021-08-15 17:29:06 +0100
committerMark Powers <mark@marks.kitchen>2021-08-15 17:29:06 +0100
commita40620d2acdd78fb6923d21ca816f16fd15a6331 (patch)
treee0203e6b15f6ac3420a475cd9b2bc1133fb8ec79 /events.py
parentaac8b0018c8985e7776eca3fb5afe7bda6781727 (diff)
Add tts engine selector, and email recordings
Diffstat (limited to 'events.py')
-rw-r--r--events.py34
1 files changed, 27 insertions, 7 deletions
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]])