在使用Qt 5.9.4的Fedora上,我无法同时记录和播放音频 [英] On Fedora using Qt 5.9.4, I'm unable to simultaneously record and play audio at the same time
问题描述
我正在尝试用Qt编写一个程序,该程序同时记录来自麦克风的音频并同时播放.我使用的是Qt 5.9.4,我使用的是Fedora 29(无法更新到最新版本,因为我们的生产环境是Fedora 29-无法更新,已经问过老板了.)
I'm trying to write a program in Qt that simultaneously records audio from a microphone and plays it back at the same time. I'm using Qt 5.9.4 and I'm on Fedora 29 (can't update to latest version as our production environment is Fedora 29 -- can't update it, have already asked boss).
我写了一些准系统代码,如下所示.但是每次我运行该程序时,都会收到以下错误消息:
I have some barebones code written, as you can see below. But everytime I run the program, I get the following error message:
using null output device, none available
using null input device, none available
我已经安装了每个qt5 *软件包.我也安装了alsa-utils和脉冲音频.
I've installed every qt5* package. I have alsa-utils and pulse audio installed as well.
我也研究了这些或多或少帮助了我但不能解决我的问题的东西:
I have also looked at these which more or less helped me but did not solve my problem:
Qt-如何同时录制和播放声音 - https://forum.qt.io/topic/10399/如何同时录制和播放声音/5
https://www.qtcentre.org/threads/45300-如何同时录制和播放声音 - Qt-无音频输出设备-Yocto/poky
- Qt +柯南=使用空输出设备,无可用
我不知道这是与Fedora有关的问题还是与Qt有关的问题.请帮忙!
I don't know if this is a fedora related issue or a Qt related issue. Please help!
myaudiorecorder.h:
myaudiorecorder.h:
#ifndef MYAUDIORECORDER_H
#define MYAUDIORECORDER_H
#include <QAudioFormat>
#include <QAudioDeviceInfo>
#include <QTextStream>
#include <QAudioInput>
#include <QAudioOutput>
#include <QObject>
class MyAudioRecorder : public QObject
{
Q_OBJECT
public:
MyAudioRecorder();
QAudioFormat formatIn;
QAudioFormat formatOut;
QAudioInput *m_audioInput;
QAudioOutput *m_audioOutput;
QAudioDeviceInfo m_InputDevice;
QAudioDeviceInfo m_OutputDevice;
QIODevice *m_input;
QIODevice *m_output;
QAudioDeviceInfo deviceIn;
QAudioDeviceInfo deviceOut;
void getFormat();
void createAudioInput();
void createAudioOutput();
void beginAudio();
};
#endif // MYAUDIORECORDER_H
myaudiorecorder.cpp:
myaudiorecorder.cpp:
#include "myaudiorecorder.h"
MyAudioRecorder::MyAudioRecorder() {
getFormat();
createAudioInput();
createAudioOutput();
}
void MyAudioRecorder::getFormat(){
formatIn.setSampleSize(8);
formatIn.setCodec("audio/pcm");
formatIn.setByteOrder(QAudioFormat::LittleEndian);
formatIn.setSampleType(QAudioFormat::UnSignedInt);
deviceIn = QAudioDeviceInfo::availableDevices(QAudio::AudioInput).at(1);
if(!deviceIn.isFormatSupported(formatIn)){
QTextStream(stdout) << " default formatIn not supported " << endl;
formatIn = deviceIn.nearestFormat(formatIn);
} else {
QTextStream(stdout) << " default formatIn supported " << endl;
}
deviceOut = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).at(0);
if(!deviceOut.isFormatSupported(formatOut)) {
QTextStream(stdout) << "1. default formatOut not supported " << endl;
formatOut = deviceOut.nearestFormat(formatOut);
}
}
void MyAudioRecorder::createAudioInput(){
m_audioInput = new QAudioInput(m_InputDevice, formatIn, 0);
}
void MyAudioRecorder::createAudioOutput(){
m_audioOutput = new QAudioOutput(m_OutputDevice, formatOut, 0);
}
void MyAudioRecorder::beginAudio(){
m_output = m_audioOutput->start();
m_input = m_audioInput->start();
}
推荐答案
void MyAudioRecorder::beginAudio(){
m_output = m_audioOutput->start();
m_audioInput->start(m_output);
//Above should do the trick but do check the volume, state and error if any:
qDebug() << "m_audioInput: volume=" << m_audioInput->volume()
<< ", state=" << m_audioInput->state()
<< ", error=" << m_audioInput->error();
qDebug() << "m_audioOutput: volume=" << m_audioOutput->volume()
<< ", state=" << m_audioOutput->state()
<< ", error=" << m_audioOutput->error();
}
这篇关于在使用Qt 5.9.4的Fedora上,我无法同时记录和播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!