Skip to content

Instantly share code, notes, and snippets.

@rbn42
Last active November 4, 2019 04:43
Show Gist options
  • Save rbn42/44bbd5bfaa88a812b13040800456aba0 to your computer and use it in GitHub Desktop.
Save rbn42/44bbd5bfaa88a812b13040800456aba0 to your computer and use it in GitHub Desktop.
An ugly example of writing to fifo file.
from PySide2 import QtMultimedia,QtWidgets
from PySide2.QtCore import QTimer,QFile,QIODevice
import sys
import os
import numpy as np
SAMPLE_RATE = 44100 # [Hz]
SAMPLE_SIZE = 16 # [bit]
CHANNEL_COUNT = 2
BUFFER_SIZE = 5000
info = QtMultimedia.QAudioDeviceInfo.defaultInputDevice()
format = info.preferredFormat()
format.setChannelCount(CHANNEL_COUNT)
format.setSampleSize(SAMPLE_SIZE)
format.setSampleRate(SAMPLE_RATE)
app = QtWidgets.QApplication(sys.argv)
audio_input = QtMultimedia.QAudioInput(format, app)
audio_input.setBufferSize(BUFFER_SIZE)
path = "/tmp/my_program.fifo"
if not os.path.exists(path):
os.mkfifo(path)
_file = QFile(path)
_file.open(QIODevice.WriteOnly)
source = audio_input.start(_file)
print('exec')
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment