오디오 레코더 예시

사용 가능한 장치와 지원되는 코덱 알아보기.

오디오 레코더는 사용 가능한 장치와 지원되는 코덱을 식별하는 방법과 QAudioRecorder 클래스의 사용법을 보여줍니다.

예제 실행하기

에서 예제를 실행하려면 Qt Creator에서 Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 예제 빌드 및 실행하기를 참조하세요.

창 및 오디오 설정 표시하기

사용자가 적절한 오디오 입력, 코덱, 컨테이너, 샘플 레이트 및 채널을 선택할 수 있는 창이 표시됩니다. 음질 또는 비트 전송률을 설정할 수 있습니다. 마지막으로 출력 파일을 선택하고 녹음을 시작할 수 있습니다.

목록은 다음 방법을 사용하여 채워집니다:

품질 슬라이더는 0(0)에서 QMediaRecorder::VeryHighQuality 까지 설정되며 기본값은 QMediaRecorder::NormalQuality 이며, 비트 전송률 상자는 목록에 하드코딩되어 있습니다.

오디오 녹음하기

오디오를 녹음하려면 QAudioRecorder 객체를 생성하기만 하면 됩니다,

audioRecorder = new QAudioRecorder(this);

를 생성하고 위에 설명한 대로 목록을 설정하면 됩니다. 녹음 및 일시 중지 버튼의 텍스트는 audioRecorder 개체의 state 상태에 따라 토글됩니다. 즉, 상태가 QMediaRecorder::StoppedState 인 경우 버튼 텍스트는 "녹음" 및 "일시 중지"가 됩니다. QMediaRecorder::RecordingState 상태에서는 녹화 버튼의 텍스트가 "중지"이고 QMediaRecorder::PausedState 상태에서는 일시 중지 버튼의 텍스트가 "다시 시작"입니다.

버튼을 누르면 상태에 따라 전환이 이루어집니다. 녹화가 중지된 경우 녹화 버튼을 누르면 audioRecorder 객체의 인코딩 설정과 컨테이너가 설정되고 record() 메서드를 사용하여 녹화가 시작됩니다.

QMediaFormat format;
format.setCodec(boxValue(ui->audioCodecBox).toString());
audioRecorder->setMediaFormat(format);
audioRecorder->setSampleRate(boxValue(ui->sampleRateBox).toInt());
audioRecorder->setBitRate(boxValue(ui->bitrateBox).toInt());
audioRecorder->setQuality(QMediaRecorder::EncodingQuality(ui->qualitySlider->value()));
audioRecorder->setEncodingMode(ui->constantQualityRadioButton->isChecked() ?
                         QMediaRecorder::ConstantQualityEncoding :
                         QMediaRecorder::ConstantBitRateEncoding);

QString container = boxValue(ui->containerBox).toString();

audioRecorder->record();

녹화하는 동안 애플리케이션의 상태 표시줄은 audioRecorder 객체의 durationChanged 신호의 지속 시간 정보로 업데이트됩니다.

ui->statusbar->showMessage(tr("Recorded %1 sec").arg(duration / 1000));

예제 프로젝트 @ code.qt.io

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.