0

I have a raspberry with a usb mic. I want to stream realtime the mic input to the 3.5mm output.

Is this possible?

2

Yes I think it is possible, for example you can use FIFO file:

~$ mkfifo /tmp/input.audio.fifo

Write a python programm like this (warning, this script record only 60sec of audio, you can adjust this): Python code REF.

To install: python -m pip install pyaudio

    """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 = 60
WAVE_OUTPUT_FILENAME = "/tmp/input.audio.fifo"

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

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

And configure the RPi audio for Jack output not HDMI then use aplay for reading the fifo file for getting your audio output (in another terminal), :

~$ aplay /tmp/input.audio.fifo

let me know if it works because I have not tried. Good luck.

Steps:

  1. Create FIFO file
  2. Configure python script audio file output with your FIFO file and run the python script. (audio input) or I think you can use arecord /tmp/input.audio.fifo instance of the python script.
  3. Use an audio player for reading the FIFO file. (audio output)
1
  • You can probably also use arecord instance of the python program : mkfifo /tmp/input.audio.fifo thenarecord - | tee /tmp/input.audio.fifo (audio INPUT) and get the output in another terminal : aplay /tmp/input.audio.fifo (audio OUTPUT) – Ephemeral Dec 12 '19 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.