/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "audiorecorder.h"
#include "ui_audiorecorder.h"
#include <QAudioProbe>
#include <QAudioRecorder>
#include <QDir>
#include <QFileDialog>
#include <QMediaRecorder>
#include <QStandardPaths>
AudioRecorder::AudioRecorder()
: ui(new Ui::AudioRecorder)
{
ui->setupUi(this);
m_audioRecorder = new QAudioRecorder(this);
m_probe = new QAudioProbe(this);
m_probe->setSource(m_audioRecorder);
///////////
//audio devices
ui->audioDeviceBox->addItem(tr("Default"), QVariant(QString()));
for (auto &device: m_audioRecorder->audioInputs()) {
ui->audioDeviceBox->addItem(device, QVariant(device));
qDebug()<<"device:"<<device;
}
///////////////
QAudioEncoderSettings settings;
settings.setCodec("");
settings.setSampleRate(44100);
settings.setChannelCount(1); //单通道
settings.setQuality(QMultimedia::NormalQuality);
m_audioRecorder->setEncodingSettings(settings, QVideoEncoderSettings(), "audio/x-wav");
connect(m_audioRecorder, &QAudioRecorder::durationChanged, this, &AudioRecorder::updateProgress);
}
void AudioRecorder::on_outputButton_clicked()
{
QString fileName = QFileDialog::getSaveFileName();
m_audioRecorder->setOutputLocation(QUrl::fromLocalFile(fileName));
}
void AudioRecorder::on_recordButton_clicked()
{
if(ui->recordButton->text() == "Record")
{
m_audioRecorder->record();
ui->recordButton->setText("Pause");
}
else if(ui->recordButton->text() == "Pause")
{
m_audioRecorder->stop();
ui->recordButton->setText("Record");
}
}
void AudioRecorder::updateProgress(qint64 duration)
{
if (m_audioRecorder->error() != QMediaRecorder::NoError || duration < 1000)
return;
ui->statusbar->showMessage(tr("Recorded %1 sec").arg(duration / 1000));
}
Qt中接收麦克风数据并保存为WAV文件
191 浏览量
2024-06-04
17:54:20
上传
评论
收藏 8KB ZIP 举报
AI+程序员在路上
- 粉丝: 2315
- 资源: 16
最新资源
- 400张高清宣纸纹理底纹素材古典中国风
- 酒店机票价格非常的便宜三
- TM2301FN-VB一款SOT23封装P-Channel场效应MOS管
- Java项目-基于SSM+JSP的网上订餐系统的设计与实现(源码+数据库脚本+部署视频+代码讲解视频+全套软件)
- 基于51单片机的DS1302与LCD1602设计的智能电子钟 闰年自动判断
- 酒店机票价格非常的便宜二
- 基于python的网络爬虫爬取天气数据及可视化分析python大作业(源码+教程)
- Java项目-基于SSM+Jsp的高校校园点餐系统的设计与实现(源码+数据库脚本+部署视频+代码讲解视频+全套软件)
- 反向编译 ★逆向工程★工具包【TOP升级版】v24.07
- 酒店机票价格非常的便宜一
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈