Esempio n. 1
0
def voiceRecorder( secs, channels, name ):
  f= open( name, 'wb' )
  # Minimum set of parameters we need to create Encoder
  cparams= { 'id': acodec.getCodecID( 'mp3' ),
             'bitrate': 128000,
             'sample_rate': 44100,
             'channels': channels } 
  ac= acodec.Encoder( cparams )
  print sound.getIDevices()[0]
  snd= sound.Input( 44100, channels, sound.AFMT_S16_LE )
  snd.start()
  
  # Loop until recorded position greater than the limit specified
  while snd.getPosition()<= secs:
    s= snd.getData()
    if s and len( s ):
      for fr in ac.encode( s ):
        # We definitely should use mux first, but for
        # simplicity reasons this way it'll work also
        f.write( fr )
    else:
      time.sleep( .003 )
  
  # Stop listening the incoming sound from the microphone or line in
  snd.stop()
Esempio n. 2
0
   def __init__(self, params=params):
      self.status = STOPPED
      self.encoder= acodec.Encoder(params)

      # determine input source
      inputid=None
      for d in sound.getIDevices():
         if d['name'] == insrc:
            inputid = d['id']
      
      if not inputid:
         raise Exception("Invalid or no input source")

      self.snd= sound.Input(22050, 1, format, inputid)
Esempio n. 3
0
 def setDevice(self, name):
    for d in sound.getIDevices():
       if d['name'] == name:
          self.deviceid = d['id']
          return
    raise Exception("Invalid device!")
Esempio n. 4
0
 def getDeviceNames(self):
    names = []
    for d in sound.getIDevices():
       names.append(d['name'])
    return names