资源简介

使用百度提供的C++sdk调试语音识别功能,安装工具有perl(安装openssl),QT(编写QT界面程序),VS2017(用于编译openssl,QT使用其编译器),curl(百度语音sdk需要此库的服务), jsoncpp,代码已调试通过

资源截图

代码片段和文件信息

#include “Audio.h“
#include 
#include 
#include 

Audio::Audio(QString filedir):m_audiofiledir(filedir)
{
    QDir dir(m_audiofiledir);
    if(!dir.exists())
    {
        dir.mkpath(m_audiofiledir);
    }



        // Set up the desired m_format for example:
        m_format.setSampleRate(16000);
        m_format.setChannelCount(1);
        m_format.setSampleSize(16);
        m_format.setCodec(“audio/pcm“);
        m_format.setByteOrder(QAudioFormat ::LittleEndian);
        m_format.setSampleType(QAudioFormat::UnSignedInt);

        QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
        if (!info.isFormatSupported(m_format)) {
            qWarning() << “Default m_format not supported trying to use the nearest.“;
            m_format = info.nearestFormat(m_format);
        }


        //connect(m_audioInput SIGNAL(stateChanged(QAudio::State)) this SLOT(handleStateChanged(QAudio::State)));

        //QTimer::singleShot(3000 this SLOT(stopRecording()));
        //audio->start(&destinationFile);
        // Records audio for 3000ms
}

void Audio::startRecording(QString filename)
{
    QString tmpdir(m_audiofiledir);
    m_audiofilename=tmpdir.append(“/“).append(filename);
    m_audioFile=new QFile(m_audiofilename);
    if(m_audioFile->isOpen())
    {
        m_audioFile->close();
        qDebug()<    }

    bool fileopen=m_audioFile->open( QIODevice::WriteOnly | QIODevice::Truncate );
    if(fileopen)
    {
        qDebug() << “open success!“;
    }
    else
    {
        qDebug() << “open failed!“;

    }
    qDebug()<fileName();
    m_audioInput = new QAudioInput(m_format);
    m_audioInput->start(m_audioFile);
}
QString Audio::stopRecording()
{
    m_audioInput->stop();
    //m_audiofilename=m_audioFile.fileName();
    m_audioFile->close();
    delete m_audioInput;
    delete m_audioFile;
    return m_audiofilename;
}
void Audio::handleStateChanged(QAudio::State newState)
{
    switch (newState) {
        case QAudio::StoppedState:
            if (m_audioOutput->error() != QAudio::NoError) {
                // Error handling
                m_audioOutput->stop();
                m_audioFile->close();
                delete m_audioOutput;
            } else {
                // Finished recording
                m_audioOutput->stop();
                m_audioFile->close();
                delete m_audioOutput;
            }
            break;

        case QAudio::ActiveState:
            // Started recording - read from IO device
            break;
        case QAudio::IdleState:
                // Finished playing (no more data)
                m_audioOutput->stop();
                m_audioFile->close();
                delete m_audioOutput;
                break;
        default:
            // ... other cases as appropriate
            brea

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-09-08 05:13  StatementRecognition\
     文件        3764  2018-09-04 23:39  StatementRecognition\Audio.cpp
     文件         751  2018-09-05 23:06  StatementRecognition\Audio.h
     目录           0  2018-09-05 00:37  StatementRecognition\base\
     文件        8465  2018-09-05 00:08  StatementRecognition\base\base.h
     文件        4308  2018-09-05 00:37  StatementRecognition\base\base64.h
     文件        8580  2018-08-23 16:45  StatementRecognition\base\http.h
     文件        8244  2018-08-23 16:45  StatementRecognition\base\utils.h
     目录           0  2018-09-06 00:19  StatementRecognition\curl\
     文件      104159  2018-07-09 08:42  StatementRecognition\curl\curl.h
     文件        3034  2018-07-11 08:00  StatementRecognition\curl\curlver.h
     文件        3473  2017-12-03 00:33  StatementRecognition\curl\easy.h
     文件        2071  2017-12-03 00:33  StatementRecognition\curl\mprintf.h
     文件       16211  2018-06-14 16:31  StatementRecognition\curl\multi.h
     文件        1329  2017-12-03 00:33  StatementRecognition\curl\stdcheaders.h
     文件       18488  2018-07-09 08:42  StatementRecognition\curl\system.h
     文件       43214  2018-07-09 08:42  StatementRecognition\curl\typecheck-gcc.h
     目录           0  2018-09-04 21:23  StatementRecognition\json\
     文件       12015  2018-09-04 21:08  StatementRecognition\json\json-forwards.h
     文件       74757  2018-09-04 21:08  StatementRecognition\json\json.h
     文件      162316  2018-09-04 21:08  StatementRecognition\jsoncpp.cpp
     目录           0  2018-09-06 00:23  StatementRecognition\lib\
     目录           0  2018-09-06 00:33  StatementRecognition\lib\debug\
     文件     3194880  2018-08-09 23:28  StatementRecognition\lib\debug\libcrypto-1_1-x64.dll
     文件      933624  2018-08-09 23:28  StatementRecognition\lib\debug\libcrypto.lib
     文件      909824  2018-09-06 00:20  StatementRecognition\lib\debug\libcurl_debug.dll
     文件       17346  2018-09-06 00:20  StatementRecognition\lib\debug\libcurl_debug.lib
     文件      628736  2018-08-09 23:28  StatementRecognition\lib\debug\libssl-1_1-x64.dll
     文件       97230  2018-08-09 23:28  StatementRecognition\lib\debug\libssl.lib
     目录           0  2018-09-06 00:33  StatementRecognition\lib\release\
     文件     3194880  2018-08-09 23:28  StatementRecognition\lib\release\libcrypto-1_1-x64.dll
............此处省略31个文件信息

评论

共有 条评论