Python pyaudio.get_sample_size() Examples

The following are 4 code examples of pyaudio.get_sample_size(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyaudio , or try the search function .
Example #1
Source File: offline_ser.py    From LIVE_SER with Apache License 2.0 6 votes vote down vote up
def predict_file(dec, pyaudio, path, frames, args, rate = 16000, format = pyaudio.paInt16, save = False):
    wf = wave.open(path, 'wb')
    wf.setnchannels(1)
    wf.setsampwidth(pyaudio.get_sample_size(format))
    wf.setframerate(rate)
    #this code works for only for pulseaudio
    #wf.writeframes(b''.join(frames))
    wf.writeframes(frames)
    wf.close()

    results = dec.predict_file(path, feat_mode = args.feat_mode, feat_dim = args.feat_dim, three_d = args.three_d)
    
    if save == False:
        os.remove(path)
    if args.predict_mode == 0:
        task_outputs = dec.returnDiff(results)
    elif args.predict_mode == 1:
        task_outputs = dec.returnLabel(results)
    else:
        task_outputs = dec.returnClassDist(results)
    return task_outputs

#main loop for speech emotion recognition 
Example #2
Source File: audio_recorder.py    From magenta with Apache License 2.0 5 votes vote down vote up
def bytes_per_sample(self):
    return pyaudio.get_sample_size(self.pyaudio_format) 
Example #3
Source File: __init__.py    From PyBaiduYuyin with MIT License 5 votes vote down vote up
def __init__(self, device_index = None):
            assert device_index is None or isinstance(device_index, int), "Device index must be None or an integer"
            if device_index is not None: # ensure device index is in range
                audio = pyaudio.PyAudio(); count = audio.get_device_count(); audio.terminate() # obtain device count
                assert 0 <= device_index < count, "Device index out of range"
            self.device_index = device_index
            self.format = pyaudio.paInt16 # 16-bit int sampling
            self.SAMPLE_WIDTH = pyaudio.get_sample_size(self.format)
            self.RATE = 16000 # sampling rate in Hertz
            self.CHANNELS = 1 # mono audio
            self.CHUNK = 1024 # number of frames stored in each buffer

            self.audio = None
            self.stream = None 
Example #4
Source File: audio_recorder.py    From project-keyword-spotter with Apache License 2.0 5 votes vote down vote up
def bytes_per_sample(self):
    return pyaudio.get_sample_size(self.pyaudio_format)