Stop tts on chat change / new recording
This commit is contained in:
parent
867c6d7e33
commit
01fe033583
|
@ -100,6 +100,7 @@
|
||||||
// clean up
|
// clean up
|
||||||
// abort any pending requests.
|
// abort any pending requests.
|
||||||
controller.abort()
|
controller.abort()
|
||||||
|
ttsStop()
|
||||||
})
|
})
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
@ -460,7 +461,7 @@
|
||||||
focusInput()
|
focusInput()
|
||||||
}
|
}
|
||||||
|
|
||||||
const tts = (text:string, recorded:boolean) => {
|
const ttsStart = (text:string, recorded:boolean) => {
|
||||||
// Use TTS to read the response, if query was recorded
|
// Use TTS to read the response, if query was recorded
|
||||||
if (recorded && 'SpeechSynthesisUtterance' in window) {
|
if (recorded && 'SpeechSynthesisUtterance' in window) {
|
||||||
const utterance = new SpeechSynthesisUtterance(text)
|
const utterance = new SpeechSynthesisUtterance(text)
|
||||||
|
@ -468,6 +469,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ttsStop = () => {
|
||||||
|
// Use TTS to read the response, if query was recorded
|
||||||
|
if ('SpeechSynthesisUtterance' in window) {
|
||||||
|
window.speechSynthesis.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const submitForm = async (recorded: boolean = false, skipInput: boolean = false): Promise<void> => {
|
const submitForm = async (recorded: boolean = false, skipInput: boolean = false): Promise<void> => {
|
||||||
// Compose the system prompt message if there are no messages yet - disabled for now
|
// Compose the system prompt message if there are no messages yet - disabled for now
|
||||||
if (updating) return
|
if (updating) return
|
||||||
|
@ -501,7 +509,7 @@
|
||||||
await response.promiseToFinish()
|
await response.promiseToFinish()
|
||||||
const message = response.getMessages()[0]
|
const message = response.getMessages()[0]
|
||||||
if (message) {
|
if (message) {
|
||||||
tts(message.content, recorded)
|
ttsStart(message.content, recorded)
|
||||||
}
|
}
|
||||||
focusInput()
|
focusInput()
|
||||||
}
|
}
|
||||||
|
@ -551,6 +559,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordToggle = () => {
|
const recordToggle = () => {
|
||||||
|
ttsStop()
|
||||||
if (updating) return
|
if (updating) return
|
||||||
// Check if already recording - if so, stop - else start
|
// Check if already recording - if so, stop - else start
|
||||||
if (recording) {
|
if (recording) {
|
||||||
|
|
Loading…
Reference in New Issue