i'm trying record sound mic. firstly used pyaudio sounddevice both failed.
here code pyaudio:
import pyaudio def _recording_loop(samples_queue, running, stream, chunk_size): stream.start_stream() while running.is_set(): samples_queue.put(stream.read(chunk_size)) stream.stop_stream() class recoder: def __init__(self, frame_rate, period): self.proc = none self.running = event() self.samples_queue = queue() self.frame_rate = frame_rate self.chunk_size = (frame_rate*period) / 1000 self.channels = 1 self._pa = pyaudio.pyaudio() self._stream = none def start(self): if self.proc none: self._stream = self._pa.open(format=pyaudio.paint8, channels=self.channels, rate=self.frame_rate, input=true, frames_per_buffer=self.chunk_size) self.running.set() self.proc = process(target=_recording_loop, args=[self.samples_queue, self.running, self._stream, self.chunk_size]) self.proc.start() def stop(self): if self.proc not none: self.running.clear() self.proc.join() self._stream.close() self._pa.terminate() def empty(self): return self.samples_queue.empty() def read(self): res = [] while not self.samples_queue.empty(): res.append(self.samples_queue.get()) return res
it gives me warning: python[21648:645093] 13:42:01.242 warning: 140: application, or library uses, using deprecated carbon component manager hosting audio units. support removed in future release. also, makes host incompatible version 3 audio units. please transition api's in audiocomponent.h.
, nothing ever recorded.
as understand it's el capitan , not solved yet. maybe i'm wrong?
so decided switch library sounddevice:
from multiprocessing import process, queue, event import sounddevice sd def _recording_loop(samples_queue, running, frame_rate, chunk_size): while running.is_set(): samples_queue.put(sd.rec(chunk_size, samplerate=frame_rate, channels=1, dtype='int8', blocking=true)) class recoder: def __init__(self, frame_rate, period): self.proc = none self.running = event() self.samples_queue = queue() self.frame_rate = frame_rate self.period = period self.chunk_size = (frame_rate * period) / 1000 def start(self): if self.proc none: self.running.set() self.proc = process(target=_recording_loop, args=[self.samples_queue, self.running, self.frame_rate, self.chunk_size]) self.proc.start() def stop(self): if self.proc not none: self.running.clear() self.proc.join() def empty(self): return self.samples_queue.empty() def read(self): res = [] while not self.samples_queue.empty(): res.append(self.samples_queue.get()) return res
and says:
||pamaccore (auhal)|| warning on line 530: err=''who?'', msg=audio hardware: unknown property ||pamaccore (auhal)|| warning on line 534: err=''who?'', msg=audio hardware: unknown property ||pamaccore (auhal)|| warning on line 445: err=''who?'', msg=audio hardware: unknown property
and again nothing recorded. i'm doing wrong?
sounddevice.rec() not meant used that. call number of frames want record , that's (see example docs):
import sounddevice sd fs = 44100 duration = 10 # seconds myrecording = sd.rec(duration * fs, samplerate=fs, channels=2, blocking=true)
that's it. don't need half page of code record sound.
btw, can ignore warning now, see https://github.com/spatialaudio/python-sounddevice/issues/10.
Comments
Post a Comment