Beispiel #1
0
from barbershop import Barbershopper
from toSoundcloud import postSoundcloud
from secrets import twilioSecrets,serverSecrets
from barberlogging import BarberLogging

logFile = 'log_twilio.log'
logger = BarberLogging(logFile, 'twilioHandler.py')

try:
	twilioClient = TwilioRestClient(twilioSecrets['SID'], twilioSecrets['TOKEN'])

	# Parse the inputs
	inputs = cgi.FieldStorage()
	audioURL = str(inputs['RecordingUrl'].value)
	callerNumber = str(inputs['Caller'].value)
	logger.log('Call recieved from (' + callerNumber + ') giving a recording url of: ' + audioURL)

	# Set up vars
	barbershopID = "%i_%i" % (int(time.time() * 1e4), int(random.random() * 1e6))
	baseURL = "http://" + serverSecrets['IP'] + "/";
	defaultWebDirectory = "/var/www/html/"
	originalAudioFile = "originalAudio_" + barbershopID + ".wav"
	barbershoppedAudioFile = "barbershoppedAudio_" + barbershopID + ".wav"

	# Download the recording
	urllib.urlretrieve(audioURL, defaultWebDirectory + originalAudioFile)
	logger.log('Downloaded ' + audioURL + ' to ' + defaultWebDirectory + originalAudioFile)

	# Do-barbershopping
	bshop = Barbershopper(barbershopID, logger)
	bshop.doBarberShopping(defaultWebDirectory + originalAudioFile, defaultWebDirectory + barbershoppedAudioFile)
Beispiel #2
0
#!/usr/bin/env python
import sys, traceback, cgi
from barberlogging import BarberLogging

try:
	inputs = cgi.FieldStorage()
	barbershoppedFile = str(inputs['file'].value)

	twimlResponse = '<?xml version="1.0" encoding="UTF-8" ?>\n<Response>\n<Play>' + barbershoppedFile + '</Play>\n</Response>'

	logger = BarberLogging('log_playback.log', 'playback.py')
	logger.log(twimlResponse)

	print('Content-type: text/xml\n')
	print(twimlResponse)
except:
	logger = BarberLogging('log_playback.log', 'playback.py - Error')
	logger.log(traceback.format_exc())

	print('Content-type: text/plain\n')
	print('Error:\n')
	print(traceback.format_exc())