-
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
Conversation
--bug=1052345 --user=刘瑞斌 【github#2352】【应用】使用浏览器内置TTS,切换历史记录内容播放会没有声音 https://www.tapd.cn/57709429/s/1657771
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
nextTick(() => { | ||
window.speechSynthesis.cancel() | ||
}) | ||
} | ||
} | ||
} | ||
if (common.isMobile()) { |
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 provided code is primarily concerned with handling chat interactions and updating audio playback state when changing chats. Here are some points to consider:
-
Suspension Handling: The
if
block checks if the browser speech synthesis is both paused and speaking (window.speechSynthesis.paused && window.speechSynthesis.speaking
) before resuming it. It then cancels any existing speech usingnextTick(
, which ensures that the next tick of the event loop runs after the cancel operation completes. -
Comments Consistency: The comments are consistent throughout the file but lack descriptions about their purpose within the context of the larger function.
-
Code Organization: The code seems well-organized for its functionality related to handling chat clicks and controlling speech synthesis.
-
Functionality Checks: Ensure there are no other parts of the application relying on this logic that might not handle changes correctly.
Overall, the code appears functional without major issues. If you need further debugging or optimization suggestions, additional testing under different conditions would be recommended.
@@ -200,7 +200,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 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,
if (window.speexSynthesis.paused && audioList.value[currentAudioIndex.value] === utterance.value?.text) {
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 if speechSynthesis
is paused:
// Check if speech is paused AND current text is different
if (window.speechSynthesis.paused && audioList.value[currentAudioIndex.value] !== utterance.value?.text) {
// Resume speech with the current text
window.speechSynthesis.resume();
}
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.
@@ -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 comment
The 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!
fix: Fix browser text to speech cannot resume and cancel --bug=1052345 --user=刘瑞斌 【github#2352】【应用】使用浏览器内置TTS,切换历史记录内容播放会没有声音 https://www.tapd.cn/57709429/s/1657771