mardi 22 mars 2016

Convert pyaudio.paint16 to float

I have data obtained by simple pyAudio recording:

"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
            channels=CHANNELS,
            rate=RATE,
            input=True,
            frames_per_buffer=CHUNK)

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
  data = stream.read(CHUNK)
  frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

and I need to process these in numpy (and not to be converted back). So I need to convert from pyaudio.paInt16 (or 24 and so on...) to something more manageable like float or double.

Is there a simple way?



Convert pyaudio.paint16 to float

Aucun commentaire:

Enregistrer un commentaire