Beispiel #1
0
def voiceRecorder(secs, 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': 2
    }
    ac = acodec.Encoder(cparams)
    snd = sound.Input(44100, 2, 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()
Beispiel #2
0
def voiceRecorder( secs, 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': 2 } 
  ac= acodec.Encoder( cparams )
  snd= sound.Input( 44100, 2, 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()
Beispiel #3
0
    def __init__(self, codec):
        """Initialisation. Create a decoder for the specified codec.
           Codec is specified by file extension. Available codecs are
           listed in pymedia.audio.acodec.extensions.
        """
        super(AudioDecoder, self).__init__()

        if float(acodec.version) > 2:
            self.codecid = acodec.getCodecId(codec)
            self.decoder = acodec.Decoder({"id": self.codecid})
        else:
            self.decoder = acodec.Decoder(codec)
Beispiel #4
0
    def __init__(self, codec):
        """Initialisation. Create a decoder for the specified codec.
           Codec is specified by file extension. Available codecs are
           listed in pymedia.audio.acodec.extensions.
        """
        super(AudioDecoder, self).__init__()

        if float(acodec.version) > 2:
            self.codecid = acodec.getCodecId(codec)
            self.decoder = acodec.Decoder( {"id":self.codecid} )
        else:
            self.decoder = acodec.Decoder( codec )
Beispiel #5
0
 def writeloop(self):
     self.file = open(defaultDir + self.name + '.tmp', 'wb' )
     self.ac= acodec.Encoder({
         'id': acodec.getCodecId( 'mp3' ),
         'bitrate': 64000,
         'sample_rate': 22050,
         'channels': 2
     })
     self.sound= sound.Input( 22050, 2, sound.AFMT_S16_LE )
     self.sound.start()
     while self.status!="stop" and sound.getPosition() <= MAX_SECONDS:
         soundbytes=self.sound.getData()
         if self.status == "record":
             if soundbytes and len(soundbytes) :
                 for frame in self.ac.encode( s ):
                   self.file.write( frame )
             else:
               time.sleep( .003 )      
     self.sound.stop()
     self.file.close()
     publish_file(self.client, self.file)
     self.status = "idle"
Beispiel #6
0
import time, sys

import pymedia.audio.sound as sound
import pymedia.audio.acodec as acodec

# constants
STOPPED   = 0
RECORDING = 1

# input params
insrc = "VIA AC'97 Audio (WAVE)"
format = sound.AFMT_U16_LE

# encoder parameters
params = {
         'id': acodec.getCodecId("mp3"),
         'bitrate': 64000,
         'sample_rate': 22050,
         'channels': 1
}


class Recorder:
   
   def __init__(self, params=params):
      self.status = STOPPED
      self.encoder= acodec.Encoder(params)

      # determine input source
      inputid=None
      for d in sound.getIDevices():