chore: Update .gitignore and add .idea folder, update npm dependencies, and improve code logic for chat history and knowledge export/import

This commit is contained in:
n4ze3m
2024-05-11 19:32:36 +05:30
parent 677aa6ef51
commit f9f621c920
18 changed files with 448 additions and 261 deletions

View File

@@ -2,7 +2,6 @@ import { useEffect, useState } from "react"
import { notification } from "antd"
import { getVoice, isSSMLEnabled } from "@/services/tts"
import { markdownToSSML } from "@/utils/markdown-to-ssml"
type VoiceOptions = {
utterance: string
}
@@ -17,16 +16,28 @@ export const useTTS = () => {
if (isSSML) {
utterance = markdownToSSML(utterance)
}
chrome.tts.speak(utterance, {
voiceName: voice,
onEvent(event) {
if (event.type === "start") {
setIsSpeaking(true)
} else if (event.type === "end") {
setIsSpeaking(false)
if (import.meta.env.BROWSER === "chrome") {
chrome.tts.speak(utterance, {
voiceName: voice,
onEvent(event) {
if (event.type === "start") {
setIsSpeaking(true)
} else if (event.type === "end") {
setIsSpeaking(false)
}
}
})
} else {
// browser tts
window.speechSynthesis.speak(new SpeechSynthesisUtterance(utterance))
window.speechSynthesis.onvoiceschanged = () => {
const voices = window.speechSynthesis.getVoices()
const voice = voices.find((v) => v.name === voice)
const utter = new SpeechSynthesisUtterance(utterance)
utter.voice = voice
window.speechSynthesis.speak(utter)
}
})
}
} catch (error) {
notification.error({
message: "Error",
@@ -36,7 +47,11 @@ export const useTTS = () => {
}
const cancel = () => {
chrome.tts.stop()
if (import.meta.env.BROWSER === "chrome") {
chrome.tts.stop()
} else {
window.speechSynthesis.cancel()
}
setIsSpeaking(false)
}