pyalsaaudio icon indicating copy to clipboard operation
pyalsaaudio copied to clipboard

Recording only happpening in 96000khz sampling rate

Open venkat-kittu opened this issue 7 years ago • 2 comments

I am trying to record audio by using code from recordtest.py but when i am executing the program my audio is recorded in sampling rate of 96000khz only. I tried keeping samplingrate to 48000, but it is not reflecting in output. How much sampling rate i kept in program always it is giving output of 96000khz only..

my code is below

from future import print_function

import sys import time import getopt import alsaaudio

if name == 'main':

f = open(sys.argv[1], 'wb')
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, device='hw:0,0')
inp.setrate(48000)
inp.setchannels(1)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(160)

loops = 5000
while loops > 0:
    loops -= 1
    # Read data from device
    l, data = inp.read()
  
    if l:
        f.write(data)
        time.sleep(0.001)

Thanks in advance.

venkat-kittu avatar Sep 17 '18 10:09 venkat-kittu

is this reproducible with v0.9, using the new method to parameterize the pcm object?

if so, what does inp.dumpinfo() say?

ossilator avatar Aug 05 '22 11:08 ossilator

I think this is an ALSA problem. If the hardware does not support 48kHz then you won't get 48kHz without defining a "virtual" device. pyalsaaudio is just a thin wrapper around ALSA.

You need to define a "plugin" in the ALSA configuration. It is best to read up on the documentation here: https://www.alsa-project.org/main/index.php/Asoundrc#Why_asoundrc.3F. And then ask questions in the ALSA forum.

RonaldAJ avatar Nov 14 '22 19:11 RonaldAJ

reporter seems to have lost interest.

closing as "presumably user error".

ossilator avatar Feb 01 '24 21:02 ossilator