Switched to sox to generate phone sounds

This commit is contained in:
klonfish 2015-05-26 23:11:05 +02:00
parent 807735a8e3
commit ccf39f69f5

View file

@ -1,12 +1,7 @@
import linphone import linphone
import time import time
import threading import threading
import subprocess
DIAL_TONE_FILE = 'freizeichen.wav'
DIAL_TONE_LEN = 5
BUSY_TONE_FILE = 'besetztzeichen.wav'
BUSY_TONE_LEN = 0.96
RINGBACK_TONE = 'weckzeichen.wav'
class PhoneEvent(object): class PhoneEvent(object):
RegInProgress,\ RegInProgress,\
@ -37,9 +32,11 @@ class PhoneInterface(object):
self.__core = linphone.Core.new(cbs, config, roconfig) self.__core = linphone.Core.new(cbs, config, roconfig)
self.__audioproc = None
# Set default parameters overriding the ones from the given config file # Set default parameters overriding the ones from the given config file
self.__core.set_user_agent('FeTAp 615', '0.1') self.__core.set_user_agent('FeTAp 615', '0.1')
self.__core.ringback = RINGBACK_TONE self.__core.ringback = ''
self.__core.max_calls = 1 self.__core.max_calls = 1
self.__core.set_call_error_tone(linphone.Reason.Busy, '') self.__core.set_call_error_tone(linphone.Reason.Busy, '')
self.__core.disable_chat(linphone.Reason.None) self.__core.disable_chat(linphone.Reason.None)
@ -122,34 +119,27 @@ class PhoneInterface(object):
def end_call(self): def end_call(self):
self.__core.terminate_call(self.__core.current_call) self.__core.terminate_call(self.__core.current_call)
def __play_loop_thread(self, filename, length, continous):
self.__core.play_local(filename)
# Start replay of file 500ms before the old playing will end
# to get more or less continous play
i = 50 if continous else 0
while self.__playing and self.__running:
# TODO: Schoener?
if i == length * 100:
self.__core.play_local(filename)
i = 0
time.sleep(0.01)
i += 1
self.__core.stop_ringing()
def __play_file(self, filename, length, continous=False):
print 'Playing file:', filename
self.__playing = True
t = threading.Thread(target=self.__play_loop_thread, args=(filename, length, continous))
t.start()
def play_dial_tone(self): def play_dial_tone(self):
self.__play_file(DIAL_TONE_FILE, DIAL_TONE_LEN, True) self.stop_playing()
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', 'sine', '425'],
env = {'AUDIODRIVER': 'alsa',
'AUDIODEV': 'default:CARD=Device'})
def play_ringback_tone(self):
self.stop_playing()
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', '1', 'sine', '425', 'pad', '4@1', 'repeat', '1000'],
env = {'AUDIODRIVER': 'alsa',
'AUDIODEV': 'default:CARD=Device'})
def play_busy_tone(self): def play_busy_tone(self):
self.__play_file(BUSY_TONE_FILE, BUSY_TONE_LEN) self.stop_playing()
self.__audioproc = subprocess.Popen(['play', '-nq', 'synth', '0.48', 'sine', '425', 'pad', '0.48@0.48', 'repeat', '1000'],
env = {'AUDIODRIVER': 'alsa',
'AUDIODEV': 'default:CARD=Device'})
def stop_playing(self): def stop_playing(self):
self.__playing = False if self.__audioproc is not None:
self.__audioproc.terminate()
if __name__ == '__main__': if __name__ == '__main__':
def event_cb(evt): def event_cb(evt):