diff --git a/test/voicetest/mainwindow.cpp b/test/voicetest/mainwindow.cpp index 20f5034d..d65d2238 100644 --- a/test/voicetest/mainwindow.cpp +++ b/test/voicetest/mainwindow.cpp @@ -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(); +} diff --git a/test/voicetest/mainwindow.h b/test/voicetest/mainwindow.h index 64a8058e..523a1af6 100644 --- a/test/voicetest/mainwindow.h +++ b/test/voicetest/mainwindow.h @@ -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; diff --git a/test/voicetest/mainwindow.ui b/test/voicetest/mainwindow.ui index f67c295d..da56a625 100644 --- a/test/voicetest/mainwindow.ui +++ b/test/voicetest/mainwindow.ui @@ -69,7 +69,7 @@ 610 - 100 + 200 181 32 @@ -78,6 +78,19 @@ refresh device list + + + + 610 + 90 + 181 + 32 + + + + stop (optional) + +