Beispiel #1
0
 def stopAudio(self):
     if audiodev is not None and audiodev.is_open():
         try:
             audiodev.close()
             self._record.close()
         except:
             logger.exception('failed to close audio device')
Beispiel #2
0
 def stopAudio(self):
     if audiodev is not None and audiodev.is_open():
         try:
             audiodev.close()
             self._record.close()
         except:
             logger.exception('failed to close audio device')
Beispiel #3
0
 def startAudio(self):
     logger.debug('starting audio device')
     try:
         self._ts = 0
         if not audiodev.is_open():
             audiodev.open(self._inout, output='default', output_channels=1, input='default', input_channels=1, format='l16', 
                           sample_rate=44100, frame_duration=20)
     except:
         logger.exception('failed to start audio device')
Beispiel #4
0
 def startAudio(self):
     logger.debug('starting audio device')
     try:
         self._ts = 0
         self._record = open('record.au', 'wb')
         if audiodev is not None and not audiodev.is_open():
             audiodev.open(self._inout, output='default', output_channels=1, input='default', input_channels=1, format='l16', 
                           sample_rate=self.sample_rate, frame_duration=20)
     except:
         logger.exception('failed to start audio device')
Beispiel #5
0
 def startAudio(self):
     logger.debug('starting audio device')
     try:
         self._ts = 0
         self._record = open('record.au', 'wb')
         if audiodev is not None and not audiodev.is_open():
             audiodev.open(self._inout, output='default', output_channels=1, input='default', input_channels=1, format='l16', 
                           sample_rate=self.sample_rate, frame_duration=20)
     except:
         logger.exception('failed to start audio device')
Beispiel #6
0
 def startAudio(self):
     logger.debug("starting audio device")
     try:
         self._ts = 0
         if not audiodev.is_open():
             audiodev.open(
                 self._inout,
                 output="default",
                 output_channels=1,
                 input="default",
                 input_channels=1,
                 format="l16",
                 sample_rate=44100,
                 frame_duration=20,
             )
     except:
         logger.exception("failed to start audio device")
Beispiel #7
0
 def stopAudio(self):
     if audiodev.is_open():
         try:
             audiodev.close()
         except:
             logger.exception('failed to close audio device')
Beispiel #8
0
def audio_proc(queue_mic,
               queue_spk,
               samplerate=48000,
               audio_in=True,
               audio_out=True):
    def inout(linear, stream_time, userdata):
        try:
            if audio_in:
                linear, userdata[2] = audiospeex.resample(
                    linear,
                    input_rate=samplerate,
                    output_rate=16000,
                    state=userdata[2])
                payload, userdata[3] = audiospeex.lin2speex(linear,
                                                            sample_rate=16000,
                                                            state=userdata[3])
                payload = '\xb2' + payload
                userdata[4] += 20  # millisec
                header = Header(time=userdata[4],
                                size=len(payload),
                                type=Message.AUDIO,
                                streamId=0)
                msg = Message(header, payload)
                queue_mic.put(msg)
        except:
            logger.exception('audio inout exception: resample, encode')

        try:
            # ignore mic input (linear) for now
            if audio_out:
                msg = queue_spk.get(block=False)
                first, payload = msg.data[0], msg.data[1:]
                if first == '\xb2':  # speex
                    linear, userdata[0] = audiospeex.speex2lin(
                        payload, sample_rate=16000, state=userdata[0])
                    linear, userdata[1] = audiospeex.resample(
                        linear,
                        input_rate=16000,
                        output_rate=samplerate,
                        state=userdata[1])
                    return linear
        except Empty:
            pass
        except:
            logger.exception('audio inout exception: decode, resample')
        return ''

    if audio_in or audio_out:
        logger.info(
            'opening audio device with samplerate=%r, audio_in=%r, audio_out=%r',
            samplerate, audio_in, audio_out)
        audiodev.open(inout,
                      output='default',
                      output_channels=1,
                      input='default',
                      input_channels=1,
                      format='l16',
                      sample_rate=samplerate,
                      frame_duration=20,
                      userdata=[None, None, None, None, 0])
    try:
        while True:
            time.sleep(10)
    finally:
        if audiodev.is_open():
            logger.info('closing audio device')
            audiodev.close()