Skip to content

Commit 175c86c

Browse files
committed
fix: modify the 'Text to Speech' reading text
modify the 'Text to Speech' reading text Log: modify the 'Text to Speech' reading text Task: https://pms.uniontech.com/task-view-378245.html
1 parent c0461e0 commit 175c86c

3 files changed

Lines changed: 7 additions & 64 deletions

File tree

src/editor/dtextedit.cpp

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
28812844
void 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

src/editor/dtextedit.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ public slots:
527527
void slotAddComment(bool checked = false);
528528
void slotCancelComment(bool checked = false);
529529
void slotVoiceReadingAction(bool checked = false);
530-
bool slotStopReadingAction(bool checked = false);
531530
void slotdictationAction(bool checked = false);
532531

533532
// 音频设备检测方法
@@ -677,7 +676,6 @@ private slots:
677676
QAction *m_openInFileManagerAction;
678677
QAction *m_toggleCommentAction;
679678
QAction *m_voiceReadingAction;
680-
QAction *m_stopReadingAction;
681679
QAction *m_dictationAction;
682680
QAction *m_translateAction;
683681
QAction *m_columnEditAction;

tests/src/editor/ut_textedit.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5701,23 +5701,6 @@ TEST_F(test_textedit, slotVoiceReadingAction)
57015701
pWindow->deleteLater();
57025702
}
57035703

5704-
//slotStopReadingAction
5705-
TEST_F(test_textedit, slotStopReadingAction)
5706-
{
5707-
Window *pWindow = new Window();
5708-
pWindow->addBlankTab(QString());
5709-
pWindow->currentWrapper()->textEditor()->insertTextEx(pWindow->currentWrapper()->textEditor()->textCursor(),
5710-
QString("Holle world.\nHolle world."));
5711-
QTextCursor textCursor = pWindow->currentWrapper()->textEditor()->textCursor();
5712-
textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
5713-
pWindow->currentWrapper()->textEditor()->setTextCursor(textCursor);
5714-
pWindow->currentWrapper()->textEditor()->slotStopReadingAction(true);
5715-
bool bRet = pWindow->currentWrapper()->textEditor()->textCursor().hasSelection();
5716-
ASSERT_TRUE(bRet == true);
5717-
5718-
pWindow->deleteLater();
5719-
}
5720-
57215704
//slotdictationAction
57225705
TEST_F(test_textedit, slotdictationAction)
57235706
{

0 commit comments

Comments
 (0)