0

DAC+ ADC Pro recorded sound pitch issue

Raspian (Buster) kernel v 4.19.97

 

After recording a 10 second audio file with Python, the resulting file is the correct length, but the audio is at the wrong pitch (as if it were playing back at half speed).  Tested playback on a separate windows machine and confirmed the issue is with the recording, and not the playback.

 

Python source below:

 

import pyaudio
import wave

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

p = pyaudio.PyAudio()

print ("Info:", p.get_default_input_device_info())

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()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()

14 comments

Please sign in to leave a comment.