-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix browser text to speech cannot resume and cancel #2378
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ const playAnswerTextPart = () => { | |
if (audioList.value[currentAudioIndex.value] !== utterance.value?.text) { | ||
window.speechSynthesis.cancel() | ||
} | ||
if (window.speechSynthesis.paused) { | ||
if (window.speechSynthesis.paused && audioList.value[currentAudioIndex.value] === utterance.value?.text) { | ||
window.speechSynthesis.resume() | ||
return | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code looks clean and properly checks whether to resume speech synthesis or cancel it based on current conditions. There are no irregularities, potential issues, or significant optimizations noted at this time. If you have any specific concerns about the implementation or need further assistance with integrating it into a larger application, feel free to ask! |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,14 @@ const clickListHandle = (item: any) => { | |
currentChatName.value = item.abstract | ||
if (currentChatId.value !== 'new') { | ||
getChatRecord() | ||
|
||
// 切换对话后,取消暂停的浏览器播放 | ||
if (window.speechSynthesis.paused && window.speechSynthesis.speaking) { | ||
window.speechSynthesis.resume() | ||
nextTick(() => { | ||
window.speechSynthesis.cancel() | ||
}) | ||
} | ||
} | ||
} | ||
if (common.isMobile()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code is primarily concerned with handling chat interactions and updating audio playback state when changing chats. Here are some points to consider:
Overall, the code appears functional without major issues. If you need further debugging or optimization suggestions, additional testing under different conditions would be recommended. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code you provided has a minor issue in the conditional logic within the
playAnswerTextPart
function:Issue:
In the updated line,
the condition is incorrect because it checks both conditions simultaneously. The intent seems to be only to resume speech synthesis only when there's an active text match, but the current check also includes
speechSynthesis.paused
, which doesn't necessarily have the correct context.Optimization/Suggestion:
To fix this, we can directly resume only if the
utterance
text matches the current audio list item and ifspeechSynthesis
is paused:This change ensures that
resume()
will only happen when the voice recognition system is idle and not speaking a previous answer, preventing unexpected resumption of a pause state due to unmatched texts.