Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem in playing the audio back from Microphone to Speaker
Qt 6.11 is out! See what's new in the release blog

Problem in playing the audio back from Microphone to Speaker

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi All,
    I have used this example code to record my voice from Microphone .."audioInput example ":http://doc.qt.nokia.com/latest/multimedia-audioinput.html 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 ))
    {
    break;
    }
    }
    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()
    {
    if(!m_audioInput)
    return;

    qint64 len = m_audioInput->bytesReady();
    
    if(len > 4096)
    {
        m_buffer.resize( len );
        len = 4096;
    }
    
    qint64 l = m_input->read(m_buffer.data(), len);
    
    tempBuff->setData( m_buffer );
    tempBuff->close();
    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved