Example #1
0
 def do_command(self, action):
     if self.ready:
         action = str(action)
         self.baresip.sendline(action)
     else:
         LOG.warning(action + " not executed!")
         LOG.error("NOT READY! please wait")
Example #2
0
 def speak(self, speech):
     if not self.call_established:
         LOG.error("Speaking without an active call!")
     else:
         LOG.info("Sending TTS for " + speech)
         self.send_audio(self.tts.get_mp3(speech))
         sleep(0.5)
Example #3
0
 def hang(self):
     if self.current_call:
         LOG.info("Hanging: " + self.current_call)
         self.do_command("/hangup")
         self.current_call = None
         self._call_status = None
     else:
         LOG.error("No active call to hang")
Example #4
0
 def mute_mic(self):
     if not self.call_established:
         LOG.error("Can not mute microphone while not in a call")
         return
     if not self.mic_muted:
         LOG.info("Muting mic")
         self.do_command("/mute")
     else:
         LOG.info("Mic already muted")
Example #5
0
 def send_dtmf(self, number):
     number = str(number)
     for n in number:
         if n not in "0123456789":
             LOG.error("invalid dtmf tone")
             return
     LOG.info("Sending dtmf tones for " + number)
     dtmf = join(tempfile.gettempdir(), number + ".wav")
     ToneGenerator().dtmf_to_wave(number, dtmf)
     self.send_audio(dtmf)
Example #6
0
 def send_audio(self, wav_file):
     if not self.call_established:
         LOG.error("Can't send audio without an active call!")
         return
     wav_file, duration = self.convert_audio(wav_file)
     # send audio stream
     LOG.info("transmitting audio")
     self.do_command("/ausrc aufile," + wav_file)
     # wait till playback ends
     sleep(duration - 0.5)
     # avoid baresip exiting
     self.do_command("/ausrc alsa,default")
Example #7
0
 def resume(self):
     if self.current_call:
         LOG.info("Resuming " + self.current_call)
         self.do_command("/resume")
     else:
         LOG.error("No active call to resume")
Example #8
0
 def hold(self):
     if self.current_call:
         LOG.info("Holding: " + self.current_call)
         self.do_command("/hold")
     else:
         LOG.error("No active call to hold")
Example #9
0
 def handle_error(self, error):
     LOG.error(error)
     if error == "failed to set audio-source (No such device)":
         self.handle_audio_stream_failure()
Example #10
0
 def handle_login_failure(self):
     LOG.error("Log in failed!")
     self.quit()