コード例 #1
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')
コード例 #2
0
ファイル: caller.py プロジェクト: msingh05/rtclite
 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')
コード例 #3
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')
コード例 #4
0
ファイル: sipcaller.py プロジェクト: gavinljj/p2p-sip
 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")
コード例 #5
0
ファイル: tts.py プロジェクト: squarewavesbelow/py-audio
    if queue:
        data = queue.pop(0)
        data, upsample = audiospeex.resample(data,
                                             input_rate=8000,
                                             output_rate=44100,
                                             state=upsample)
        return data
    return ""


data = audiotts.convert(text)
duration = len(data) / 320 * 0.020
while data:
    queue.append(data[:320])
    data = data[320:]

audiodev.open(output="default",
              format="l16",
              sample_rate=44100,
              frame_duration=20,
              output_channels=1,
              input_channels=1,
              callback=inout)

try:
    time.sleep(duration)
except KeyboardInterrupt:
    audiodev.close()

del upsample
コード例 #6
0
ファイル: audio.py プロジェクト: rreusser/lifx-server
            'saturation': 0.4,
            'fadeTime': 0 if hueChange else 300
          }
        })
      

    #print '*'*int(bigness*10)

    return np.chararray.tostring(data*0)

  except KeyboardInterrupt:
    pass
  except:
    print traceback.print_exc()
    return ""


audiodev.open(output="default", input="default",
          format="l16", sample_rate=44100, frame_duration=20,
          output_channels=2, input_channels=1, flags=0x01, callback=inout)

try:
  while True:
    time.sleep(10)
except KeyboardInterrupt:
  audiodev.close()


#pl.plot(levels)
#pl.show()
コード例 #7
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()