0

I've been trying to work on a project to detect time shift between two streaming audio signals. I worked with python3, Pyaudio and I'm using a Motux828 sound card with a Neumann KU-100 microphone which takes a stereo input. So when i check my input_device_index I am the correct one which is the 4th one connnected to MOTU soundcard.

However when i record with:

import time
import pyaudio
import wave


CHUNK = 1024 * 3  # Chunk is the bytes which are currently processed
FORMAT = pyaudio.paInt16
RATE = 44100
RECORD_SECONDS = 2
WAVE_OUTPUT = "temp.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,channels=2,rate=RATE,input=True,frames_per_buffer=CHUNK,input_device_index=4)

frames = []  # np array storing all the data

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




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

wavef = wave.open(WAVE_OUTPUT, 'wb')  # opening the file
wavef.setnchannels(1)
wavef.setsampwidth(p.get_sample_size(FORMAT))
wavef.setframerate(RATE)
wavef.writeframes(b''.join(frames1))  # writing the data to be saved
wavef.close()

I record a wave file with no sound, with almost no noise(naturally)

Also I can record with 3rd party softwares with the specific microphone. It works completely, fine.

NOTE: Sound card is 24-bit depth normally, I also tried paInt24 that records a wave file with pure noise

Omer Kaya
  • 1
  • 1
  • Wrong input device , some missing `sub index`, which input channell redirect to where ? Need manage input devices before using, on linux need redirect to `ALSA`. – dsgdfg Dec 08 '16 at 16:25
  • You could use [plot_input.py](https://github.com/spatialaudio/python-sounddevice/blob/master/examples/plot_input.py) to see if there is actually a signal on your input device. – Matthias Dec 09 '16 at 22:48

1 Answers1

0

I think u mentioned wrong variable names as i seen your code. The wrong variables are :

data = stream1.read(CHUNK) 
frames.append(data1)
wavef.writeframes(b''.join(frames1))

the correct values are :

data = stream.read(CHUNK)
frames.append(data)
wavef.writeframes(b''.join(frames))
shiva
  • 5,083
  • 5
  • 23
  • 42