Skip to content

Commit

Permalink
fix for firefox, which doesn't support speech recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
jbilcke-hf committed Aug 29, 2024
1 parent cbc48bf commit 957cfa3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useQueryStringLoader() {
processUserMessage(message)
} else if (fileUrl) {
console.log(`loading ${fileUrl}`)
if (fileUrl.toLocaleLowerCase().includes(".clap")) {
if (fileUrl.toLocaleLowerCase().includes('.clap')) {
console.log(`loading clap file`)
await openClapUrl(fileUrl)
} else {
Expand All @@ -36,5 +36,12 @@ export function useQueryStringLoader() {
return
}
})()
}, [prompt, openClapUrl, openScreenplayUrl, fileUrl, interactive, imageStrategy])
}, [
prompt,
openClapUrl,
openScreenplayUrl,
fileUrl,
interactive,
imageStrategy,
])
}
28 changes: 18 additions & 10 deletions packages/app/src/services/mic/useMic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,29 @@ export const useMic = create<MicStore>((set, get) => ({
init: () => {
const { interimResults, lang, continuous, grammar, grammarWeight } = get()

// Initialize webkitSpeechRecognition
const recognition: SpeechRecognition = new (window.SpeechRecognition ||
window.webkitSpeechRecognition)()

if (!recognition) {
try {
// Initialize webkitSpeechRecognition
const recognition: SpeechRecognition = new (window.SpeechRecognition ||
window.webkitSpeechRecognition)()

if (!recognition) {
set({
isSupported: false,
error: "this browser doesn't support speech recognition",
})
return
} else {
set({
isSupported: true,
error: '',
})
}
} catch (err) {
set({
isSupported: false,
error: "this browser doesn't support speech recognition",
})
return
} else {
set({
isSupported: true,
error: '',
})
}

recognition.interimResults = true
Expand Down

0 comments on commit 957cfa3

Please sign in to comment.