1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

更新QQt 音频控制模块的用例 voicetest

This commit is contained in:
tianduanrui 2018-02-10 10:59:35 +08:00
parent 6b816fa843
commit a487f2fc7d
3 changed files with 49 additions and 7 deletions

View File

@ -112,8 +112,6 @@ void MainWindow::on_pushButton_2_clicked()
ui->inputListWidget->addItem ( adInfo.deviceName() );
}
ui->inputListWidget->setCurrentRow ( 0 );
ui->outputListWidget->clear();
@ -128,8 +126,6 @@ void MainWindow::on_pushButton_2_clicked()
ui->outputListWidget->addItem ( adInfo.deviceName() );
}
ui->outputListWidget->setCurrentRow ( 0 );
}
void MainWindow::currentInputRowChanged ( QModelIndex cur, QModelIndex )
@ -214,18 +210,43 @@ void MainWindow::currentOutputRowChanged ( QModelIndex cur, QModelIndex )
void MainWindow::on_pushButton_clicked()
{
/*这里是自定义输入、输出设备*/
QString name = ui->inputListWidget->currentIndex().data().toString();
QAudioDeviceInfo dev = findInputAudioDeviceInfoByName ( name );
name = ui->outputListWidget->currentIndex().data().toString();
QAudioDeviceInfo devOut = findOutputAudioDeviceInfoByName ( name );
manager.inputAudioFormat() = dev.preferredFormat();
manager.outputAudioFormat() = devOut.preferredFormat();
/*使用默认输入、输出设备*/
//如果开启这段代码,页面上的输入、输出设备选择,就仅仅是个显示了,不具备操作能力。
/*
dev = QQtAudioManager::defaultInputDevice();
devOut = QQtAudioManager::defaultOutputDevice();
*/
//把设备设进manager去
manager.inputDeviceInfo() = dev;
manager.outputDeviceInfo() = devOut;
//这里保证输入、输出使用格式相等 或者 不同
//如果格式不同在mac电脑上本地输入输出设备是可以使用的但是对于连接的语音蓝牙话筒却是不可以使用的原因未知。
//格式相同的时候,实在是太好用啦。
//这个建议默认就相同但是在QQtAudioManager当中并没有直接将其相等处理如果用户在readyRead槽函数里可以更改采样率进行某些特殊处理。一般不需要差异处理的相等就行了。
manager.inputAudioFormat() = manager.outputDeviceInfo().preferredFormat();
manager.outputAudioFormat() = manager.outputDeviceInfo().preferredFormat();
pline() << "in prefer" << dev.preferredFormat().channelCount() << dev.preferredFormat().sampleRate() <<
dev.preferredFormat().sampleSize();
pline() << "out prefer" << devOut.preferredFormat().channelCount() << devOut.preferredFormat().sampleRate() <<
devOut.preferredFormat().sampleSize();
pline() << "in" << manager.inputAudioFormat().channelCount() << manager.inputAudioFormat().sampleRate() <<
manager.inputAudioFormat().sampleSize();
pline() << "out" << manager.outputAudioFormat().channelCount() << manager.outputAudioFormat().sampleRate() <<
manager.outputAudioFormat().sampleSize();
manager.startInput();
manager.startOutput();
}
@ -235,3 +256,9 @@ void MainWindow::readyRead()
QByteArray bytes = manager.readStreamBytes();
manager.writeStreamBytes ( bytes );
}
void MainWindow::on_pushButton_3_clicked()
{
manager.stopOutput();
manager.stopInput();
}

View File

@ -26,6 +26,8 @@ private slots:
void currentOutputRowChanged ( QModelIndex, QModelIndex );
void on_pushButton_clicked();
void readyRead();
void on_pushButton_3_clicked();
private:
Ui::MainWindow* ui;
QQtAudioManager manager;

View File

@ -69,7 +69,7 @@
<property name="geometry">
<rect>
<x>610</x>
<y>100</y>
<y>200</y>
<width>181</width>
<height>32</height>
</rect>
@ -78,6 +78,19 @@
<string>refresh device list</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_3">
<property name="geometry">
<rect>
<x>610</x>
<y>90</y>
<width>181</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>stop (optional)</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>