Skip to content

Instantly share code, notes, and snippets.

@Evidlo
Created November 5, 2018 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Evidlo/44c3825b0e26889c1ad1de0411239e06 to your computer and use it in GitHub Desktop.
Save Evidlo/44c3825b0e26889c1ad1de0411239e06 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Evan Widloski - 2018-11-02
# Auto answer any call and play a prerecorded message
from __future__ import print_function
from twisted.internet import protocol
from twisted.internet import reactor
import time
import re
import pyte
import soundcard
import numpy as np
from scipy.io.wavfile import read
x = read('12345.wav')
from auth import username, password
screen = pyte.Screen(80, 24)
stream = pyte.Stream(screen)
s = soundcard.all_speakers()[0]
class MyPP(protocol.ProcessProtocol):
def __init__(self):
self.ran = False
self.ran2 = False
def outReceived(self, data):
print("outReceived! with %d bytes!" % len(data))
print(type(data))
stream.feed(data.decode('utf8'))
# stream.feed(data)
# self.data = self.data + data
# if b'Enter password' in data:
if True and not self.ran:
# self.transport.write("/".encode('utf8'))
self.transport.write(password.encode('utf8'))
self.transport.write("\033[C".encode('utf8'))
self.transport.write("\033[C".encode('utf8'))
time.sleep(3)
self.transport.write("\r\n".encode('utf8'))
# self.transport.write(b'x')
# time.sleep(3)
self.ran = True
elif b'Accept' in data:
print('saw accept-------------')
if not self.ran2:
print('accepting-------------')
self.transport.write("\x1b2".encode('utf8'))
self.transport.write("\033[D".encode('utf8'))
self.transport.write("\033[D".encode('utf8'))
self.transport.write("\r\n".encode('utf8'))
self.ran2 = True
self.ran3 = False
elif b'Hangup' in data:
print('connected-------------')
time.sleep(5)
s.play(x[1] / np.max(x[1]), samplerate=8000)
self.ran2 = False
self.ran3 = True
elif b'terminated' in data and not self.ran3:
print('call terminated------------')
self.ran3 = False
self.ran4 = True
with open('/tmp/dump', 'w') as f:
for line in screen.display:
f.write(line)
f.write('\n')
# print("I saw %s lines" % str(lines))
def processEnded(self, reason):
print("processEnded, status %d" % (reason.value.exitCode,))
print("quitting")
reactor.stop()
pp = MyPP()
reactor.spawnProcess(pp, "finch", [' '], None)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment