Prepare application for production deployment with enhanced voice features
Adds production environment configuration, global type declarations, and enhances voice recognition error handling and result processing. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ff0be73b-afdd-4747-978b-bb8301fb0a82 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/4b7360ad-65af-421c-ae9c-12d0b5534ad8.jpg
This commit is contained in:
@@ -79,7 +79,7 @@ export function useEnhancedVoice() {
|
||||
console.log('Voice recognition ended');
|
||||
};
|
||||
|
||||
recognition.onerror = (event) => {
|
||||
recognition.onerror = (event: SpeechRecognitionErrorEvent) => {
|
||||
console.error('Voice recognition error:', event.error);
|
||||
setIsListening(false);
|
||||
if (event.error === 'no-speech') {
|
||||
@@ -91,17 +91,22 @@ export function useEnhancedVoice() {
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onresult = (event) => {
|
||||
recognition.onresult = (event: SpeechRecognitionEvent) => {
|
||||
let finalTranscript = '';
|
||||
let interimTranscript = '';
|
||||
|
||||
for (let i = event.resultIndex; i < event.results.length; i++) {
|
||||
const result = event.results[i];
|
||||
const transcript = result[0].transcript;
|
||||
if (!result) continue;
|
||||
|
||||
const alternative = result[0];
|
||||
if (!alternative) continue;
|
||||
|
||||
const transcript = alternative.transcript;
|
||||
|
||||
if (result.isFinal) {
|
||||
finalTranscript += transcript;
|
||||
if (result[0].confidence >= settings.confidenceThreshold) {
|
||||
if (alternative.confidence >= settings.confidenceThreshold) {
|
||||
processVoiceCommand(transcript, result[0].confidence);
|
||||
}
|
||||
} else {
|
||||
|
||||
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
// Global type declarations for production environment
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
SpeechRecognition: typeof SpeechRecognition;
|
||||
webkitSpeechRecognition: typeof SpeechRecognition;
|
||||
}
|
||||
|
||||
interface SpeechRecognition extends EventTarget {
|
||||
continuous: boolean;
|
||||
grammars: SpeechGrammarList;
|
||||
interimResults: boolean;
|
||||
lang: string;
|
||||
maxAlternatives: number;
|
||||
serviceURI: string;
|
||||
start(): void;
|
||||
stop(): void;
|
||||
abort(): void;
|
||||
onaudiostart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onaudioend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onerror: ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => any) | null;
|
||||
onnomatch: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
|
||||
onresult: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
|
||||
onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onspeechstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onspeechend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
}
|
||||
|
||||
var SpeechRecognition: {
|
||||
prototype: SpeechRecognition;
|
||||
new(): SpeechRecognition;
|
||||
};
|
||||
|
||||
interface SpeechRecognitionEvent extends Event {
|
||||
readonly resultIndex: number;
|
||||
readonly results: SpeechRecognitionResultList;
|
||||
}
|
||||
|
||||
interface SpeechRecognitionErrorEvent extends Event {
|
||||
readonly error: string;
|
||||
readonly message: string;
|
||||
}
|
||||
|
||||
interface SpeechRecognitionResult {
|
||||
readonly isFinal: boolean;
|
||||
readonly length: number;
|
||||
item(index: number): SpeechRecognitionAlternative;
|
||||
[index: number]: SpeechRecognitionAlternative;
|
||||
}
|
||||
|
||||
interface SpeechRecognitionResultList {
|
||||
readonly length: number;
|
||||
item(index: number): SpeechRecognitionResult;
|
||||
[index: number]: SpeechRecognitionResult;
|
||||
}
|
||||
|
||||
interface SpeechRecognitionAlternative {
|
||||
readonly transcript: string;
|
||||
readonly confidence: number;
|
||||
}
|
||||
|
||||
interface SpeechGrammarList {
|
||||
readonly length: number;
|
||||
item(index: number): SpeechGrammar;
|
||||
[index: number]: SpeechGrammar;
|
||||
addFromURI(src: string, weight?: number): void;
|
||||
addFromString(string: string, weight?: number): void;
|
||||
}
|
||||
|
||||
interface SpeechGrammar {
|
||||
src: string;
|
||||
weight: number;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
Reference in New Issue
Block a user