Merge pull request #29 from invitecomm/master

Updated 'RECORD FILE' syntax, included silence detection value
master
Randall Degges 2016-09-11 21:46:46 -07:00 committed by GitHub
commit 5f37f3ee61
1 changed files with 15 additions and 11 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python2 #! /usr/bin/env python
# vim: set et sw=4: # -*- coding: utf-8 -*-
# vim: set et sw=4 fenc=utf-8:
""" """
.. module:: agi .. module:: agi
:synopsis: This module contains functions and classes to implment AGI scripts in python. :synopsis: This module contains functions and classes to implment AGI scripts in python.
@ -124,7 +125,7 @@ class AGI:
string = str(string) string = str(string)
if isinstance(string, float): if isinstance(string, float):
string = str(string) string = str(string)
return ''.join(['"', string.encode('ascii', 'ignore'), '"']) return ''.join(['"', string.encode('utf8', 'ignore'), '"'])
def _handle_sighup(self, signum, frame): def _handle_sighup(self, signum, frame):
"""Handle the SIGHUP signal""" """Handle the SIGHUP signal"""
@ -493,17 +494,20 @@ class AGI:
self.set_extension(extension) self.set_extension(extension)
self.set_priority(priority) self.set_priority(priority)
def record_file(self, filename, format='gsm', escape_digits='#', timeout=DEFAULT_RECORD, offset=0, beep='beep'): def record_file(self, filename, format='gsm', escape_digits='#', timeout=DEFAULT_RECORD, offset=0, beep='beep', silence=0):
"""agi.record_file(filename, format, escape_digits, timeout=DEFAULT_TIMEOUT, offset=0, beep='beep') --> None """agi.record_file(filename, format, escape_digits, timeout=DEFAULT_TIMEOUT, offset=0, beep='beep', silence=0) --> None
Record to a file until a given dtmf digit in the sequence is received Record to a file until a given dtmf digit in the sequence is received. Returns
The format will specify what kind of file will be recorded. The timeout '-1' on hangup or error. The format will specify what kind of file will be
is the maximum record time in milliseconds, or -1 for no timeout. Offset recorded. The <timeout> is the maximum record time in milliseconds, or '-1'
samples is optional, and if provided will seek to the offset without for no <timeout>. <offset samples> is optional, and, if provided, will seek
exceeding the end of the file to the offset without exceeding the end of the file. <silence> is the number
of seconds of silence allowed before the function returns despite the lack
of dtmf digits or reaching <timeout>. <silence> value must be preceded by
's=' and is also optional.
""" """
escape_digits = self._process_digit_list(escape_digits) escape_digits = self._process_digit_list(escape_digits)
res = self.execute('RECORD FILE', self._quote(filename), format, res = self.execute('RECORD FILE', self._quote(filename), format,
escape_digits, timeout, offset, beep)['result'][0] escape_digits, timeout, offset, beep, ('s=%s' % silence))['result'][0]
try: try:
return chr(int(res)) return chr(int(res))
except: except: