Problem in playing the audio back from Microphone to Speaker

  • Hi All,
    I have used this example code to record my voice from Microphone .."audioInput example ": and added few more codes to play back the recorded voice from the buffer (QByteArray ) thru speaker.

    my codes are ..


    void InputTest::createAudioOutput()
    QAudioDeviceInfo deviceInfo;
    foreach( deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
    if( deviceInfo.deviceName().contains( "Realtek HD Audio output", Qt::CaseInsensitive ))
    qDebug() << "Current Devices"<<deviceInfo.deviceName();
    if (!deviceInfo.isFormatSupported(m_format))
    qWarning()<<"default format not supported try to use nearest";
    m_format = deviceInfo.nearestFormat(m_format);

    qDebug()<<"Start of createaudioOutput";
    m_audioOutput = new QAudioOutput(deviceInfo, m_format, this);
    connect(m_audioOutput, SIGNAL(notify()), SLOT(outputNotified()));
    connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State)));
    qDebug()<<"End  of createaudioOutput";


    // in Constrcutor

    tempBuff = new QBuffer( this );
    tempBuff->open( QIODevice::ReadWrite );

    // and i have overridded the existing readMore function

    void InputTest::readMore()

    qint64 len = m_audioInput->bytesReady();
    if(len > 4096)
        m_buffer.resize( len );
        len = 4096;
    qint64 l = m_input->read(, len);
    tempBuff->setData( m_buffer );
    QIODevice *io =  m_audioOutput->start();
    io->write( tempBuff->buffer() );
    if(l > 0)
        qint64 nSize =  m_audioInfo->write(m_buffer.constData(), l);
        const char * data = m_buffer.constData();
        QByteArray tempByteArr =  m_buffer.toHex();
        textEdit->setText( QVariant( tempByteArr ).toString() );



    But ..i am not getting any response in my speaker..
    and i am always getting the State as 3 : "QAudio::UnderrunError 3 Audio data is not being fed to the audio device at a fast enough rate"

    Please let me know whether i am doing anything wrong on this.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.