0

我正在尝试在 Qt 中编写一个程序,该程序同时记录来自麦克风的音频并同时播放。我正在使用 Qt 5.9.4 并且我在 Fedora 29 上(无法更新到最新版本,因为我们的生产环境是 Fedora 29 - 无法更新,已经问过老板了)。

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

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

我已经安装了每个 qt5* 包。我也安装了 alsa-utils 和脉冲音频。

我还查看了这些或多或少对我有帮助但没有解决我的问题的方法:

我不知道这是与 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();
}
4

2 回答 2

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

}
于 2020-02-25T18:26:16.403 回答
0

您需要将 qt Qt/5.9.x/mingw73_64/plugins/audio 复制到您的二进制目录,而不是复制 qtaudio_windows.dll ,是复制音频文件夹

于 2020-04-14T20:29:42.763 回答