diff --git a/src/components/ChatInterface.tsx b/src/components/ChatInterface.tsx index 9220054..04e52f6 100644 --- a/src/components/ChatInterface.tsx +++ b/src/components/ChatInterface.tsx @@ -57,19 +57,19 @@ export const ChatInterface: React.FC = ({ onCreateTicket }) console.warn('SpeechRecognition is not supported in this browser.'); } }, []); - + const speak = (text: string) => { - if ('speechSynthesis' in window) { - const utterance = new SpeechSynthesisUtterance(text); - utterance.lang = 'en-US'; - utterance.pitch = 1; - utterance.rate = 1; - utterance.volume = 1; - window.speechSynthesis.speak(utterance); - } else { - console.warn('Speech synthesis not supported in this browser.'); - } -}; + if ('speechSynthesis' in window) { + const utterance = new SpeechSynthesisUtterance(text); + utterance.lang = 'en-US'; + utterance.pitch = 1; + utterance.rate = 1; + utterance.volume = 1; + window.speechSynthesis.speak(utterance); + } else { + console.warn('Speech synthesis not supported in this browser.'); + } + }; const handleSend = async (messageOverride?: string) => { const messageToSend = messageOverride ?? input; @@ -121,14 +121,20 @@ export const ChatInterface: React.FC = ({ onCreateTicket }) }; const handleMicClick = () => { - if (recognitionRef.current) { - if (isListening) { - recognitionRef.current.stop(); - } else { - recognitionRef.current.start(); + if (recognitionRef.current) { + if (isListening) { + recognitionRef.current.stop(); + } else { + recognitionRef.current.start(); + } } - } -}; + }; + + const handleStopListening = () => { + if ('speechSynthesis' in window) { + window.speechSynthesis.cancel(); + } + }; const handleCreateTicketFromChat = async () => { @@ -182,7 +188,7 @@ export const ChatInterface: React.FC = ({ onCreateTicket })

Ask me anything about IT issues

- + {messages.length > 1 && !showTicketForm && ( )} - + {message.role === 'user' && (
@@ -225,7 +231,7 @@ export const ChatInterface: React.FC = ({ onCreateTicket }) )}
))} - + {isLoading && (
@@ -247,7 +253,7 @@ export const ChatInterface: React.FC = ({ onCreateTicket })

Create Support Ticket

- +
= ({ onCreateTicket }) className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500" disabled={isCreatingTicket} /> - + = ({ onCreateTicket }) className="w-full px-3 py-2 bg-gray-700 border border-gray-600 rounded text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500" disabled={isCreatingTicket} /> - +
- +
)} - +
@@ -315,35 +321,35 @@ export const ChatInterface: React.FC = ({ onCreateTicket }) />
- - + disabled={isLoading} + title={isListening ? "Stop Listening" : "Start Voice Input"} + > + {isListening ? ( + + ) : ( + + )} + + {isListening && ( + Listening... + )} + - -
+ +
diff --git a/src/services/speechService.ts b/src/services/speechService.ts index dcf7ff8..870d596 100644 --- a/src/services/speechService.ts +++ b/src/services/speechService.ts @@ -23,6 +23,7 @@ export class SpeechService { onError: (error: string) => void ): void { if (!this.recognition || this.isListening) return; + this.recognition.onresult = (event) => { let transcript = '';