Last active
November 4, 2019 04:43
-
-
Save rbn42/44bbd5bfaa88a812b13040800456aba0 to your computer and use it in GitHub Desktop.
An ugly example of writing to fifo file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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