@@ -299,7 +299,6 @@ void TextEdit::initRightClickedMenu()
299299 m_openInFileManagerAction = new QAction (tr (" Display in file manager" ), this );
300300 m_toggleCommentAction = new QAction (tr (" Add Comment" ), this );
301301 m_voiceReadingAction = new QAction (tr (" Text to Speech" ), this );
302- m_stopReadingAction = new QAction (tr (" Stop reading" ), this );
303302 m_dictationAction = new QAction (tr (" Speech to Text" ), this );
304303 m_translateAction = new QAction (tr (" Translate" ), this );
305304 m_columnEditAction = new QAction (tr (" Column Mode" ), this );
@@ -375,7 +374,6 @@ void TextEdit::initRightClickedMenu()
375374 connect (m_addComment, &QAction::triggered, this , &TextEdit::slotAddComment);
376375 connect (m_cancelComment, &QAction::triggered, this , &TextEdit::slotCancelComment);
377376 connect (m_voiceReadingAction, &QAction::triggered, this , &TextEdit::slotVoiceReadingAction);
378- connect (m_stopReadingAction, &QAction::triggered, this , &TextEdit::slotStopReadingAction);
379377 connect (m_dictationAction, &QAction::triggered, this , &TextEdit::slotdictationAction);
380378 connect (m_translateAction, &QAction::triggered, this , &TextEdit::slot_translate);
381379 connect (m_columnEditAction, &QAction::triggered, this , &TextEdit::slotColumnEditAction);
@@ -537,23 +535,9 @@ void TextEdit::popRightMenu(QPoint pos)
537535 (DSysInfo::uosEditionType() == DSysInfo::UosEdition::UosHome) ||
538536 (DSysInfo::uosEditionType() == DSysInfo::UosEdition::UosEducation)) {*/
539537
540- bool stopReadingState = false ;
541- QDBusMessage stopReadingMsg = QDBusMessage::createMethodCall (" com.iflytek.aiassistant" ,
542- " /aiassistant/tts" ,
543- " com.iflytek.aiassistant.tts" ,
544- " isTTSInWorking" );
538+ m_rightMenu->addAction (m_voiceReadingAction);
539+ m_voiceReadingAction->setEnabled (true );
545540
546- QDBusReply<bool > stopReadingStateRet = QDBusConnection::sessionBus ().asyncCall (stopReadingMsg, 100 );
547- if (stopReadingStateRet.isValid ()) {
548- stopReadingState = stopReadingStateRet.value ();
549- }
550- if (!stopReadingState) {
551- m_rightMenu->addAction (m_voiceReadingAction);
552- m_voiceReadingAction->setEnabled (false );
553- } else {
554- m_rightMenu->removeAction (m_voiceReadingAction);
555- m_rightMenu->addAction (m_stopReadingAction);
556- }
557541 bool voiceReadingState = false ;
558542 QDBusMessage voiceReadingMsg = QDBusMessage::createMethodCall (" com.iflytek.aiassistant" ,
559543 " /aiassistant/tts" ,
@@ -2847,37 +2831,16 @@ void TextEdit::slotVoiceReadingAction(bool checked)
28472831#endif
28482832 return ;
28492833 }
2834+
2835+ // 先结束之前的播放
2836+ QProcess process;
2837+ process.start (" dbus-send" , QStringList () << " --print-reply" << " --dest=com.iflytek.aiassistant" << " /aiassistant/tts" << " com.iflytek.aiassistant.tts.stopTTSDirectly" );
2838+ process.waitForFinished (1000 ); // 最多等待1秒
28502839
28512840 QProcess::startDetached (" dbus-send --print-reply --dest=com.iflytek.aiassistant /aiassistant/deepinmain com.iflytek.aiassistant.mainWindow.TextToSpeech" );
28522841 emit signal_readingPath ();
28532842}
28542843
2855- bool TextEdit::slotStopReadingAction (bool checked)
2856- {
2857- Q_UNUSED (checked);
2858- bool voiceReadingState = false ;
2859- QDBusMessage voiceReadingMsg = QDBusMessage::createMethodCall (" com.iflytek.aiassistant" ,
2860- " /aiassistant/tts" ,
2861- " com.iflytek.aiassistant.tts" ,
2862- " getTTSEnable" );
2863-
2864- QDBusReply<bool > voiceReadingStateRet = QDBusConnection::sessionBus ().asyncCall (voiceReadingMsg, 100 );
2865- // 没有收到返回就加载配置文件数据
2866- if (voiceReadingStateRet.isValid ()) {
2867- voiceReadingState = voiceReadingStateRet.value ();
2868- }
2869- if (!voiceReadingState) {
2870- #ifdef DTKWIDGET_CLASS_DSizeMode
2871- Utils::sendFloatMessageFixedFont (this , QIcon (" :/images/warning.svg" ), tr (" Please install UOS AI from the app store first." ));
2872- #else
2873- DMessageManager::instance ()->sendMessage (this , QIcon (" :/images/warning.svg" ), tr (" Please install UOS AI from the app store first." ));
2874- #endif
2875- return false ;
2876- }
2877-
2878- return QProcess::startDetached (" dbus-send --print-reply --dest=com.iflytek.aiassistant /aiassistant/tts com.iflytek.aiassistant.tts.stopTTSDirectly" );
2879- }
2880-
28812844void TextEdit::slotdictationAction (bool checked)
28822845{
28832846 Q_UNUSED (checked);
@@ -8209,7 +8172,6 @@ void TextEdit::onAudioPortEnabledChanged(quint32 cardId, const QString &portName
82098172
82108173 // 如果所有输出设备都被禁用,显示输出设备提示
82118174 if (!hasOutputDevice) {
8212- slotStopReadingAction ();
82138175#ifdef DTKWIDGET_CLASS_DSizeMode
82148176 Utils::sendFloatMessageFixedFont (this , QIcon (" :/images/warning.svg" ), tr (" No audio output device was detected. Please ensure your speakers or headphones are properly connected and try again." ));
82158177#else
0 commit comments