在使用 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 -- 无法更新,已经问过老板)。

我写了一些准系统代码,如下所示。但是每次我 运行 程序,我都会收到以下错误消息:

using null output device, none available
using null input device, none available

我已经安装了每个 qt5* 包。我也安装了 alsa-utils 和 pulse audio。

我也看了这些,或多或少对我有帮助,但没有解决我的问题:

我不知道这是fedora相关的问题还是Qt相关的问题。请帮忙!

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:

#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 Qt/5.9.x/mingw73_64/plugins/audio到你的二进制目录,不是复制qtaudio_windows.dll,是复制音频文件夹