mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
Added speech recognition to prompt box
This commit is contained in:
parent
eda10b1212
commit
b0b9028b1f
@ -7,6 +7,7 @@ import { Workbench } from '~/components/workbench/Workbench.client';
|
|||||||
import { classNames } from '~/utils/classNames';
|
import { classNames } from '~/utils/classNames';
|
||||||
import { Messages } from './Messages.client';
|
import { Messages } from './Messages.client';
|
||||||
import { SendButton } from './SendButton.client';
|
import { SendButton } from './SendButton.client';
|
||||||
|
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition'; // Import SpeechRecognition
|
||||||
|
|
||||||
import styles from './BaseChat.module.scss';
|
import styles from './BaseChat.module.scss';
|
||||||
|
|
||||||
@ -59,6 +60,17 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|||||||
) => {
|
) => {
|
||||||
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
|
const TEXTAREA_MAX_HEIGHT = chatStarted ? 400 : 200;
|
||||||
|
|
||||||
|
// SpeechRecognition hooks
|
||||||
|
const { transcript, listening, resetTranscript } = useSpeechRecognition();
|
||||||
|
|
||||||
|
const handleStartListening = () => {
|
||||||
|
SpeechRecognition.startListening({ continuous: true, language: 'en-US' });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStopListening = () => {
|
||||||
|
SpeechRecognition.stopListening();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@ -122,7 +134,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
|
|||||||
sendMessage?.(event);
|
sendMessage?.(event);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
value={input}
|
value={input || transcript}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
handleInputChange?.(event);
|
handleInputChange?.(event);
|
||||||
}}
|
}}
|
||||||
|
23620
package-lock.json
generated
Normal file
23620
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -74,7 +74,8 @@
|
|||||||
"remix-island": "^0.2.0",
|
"remix-island": "^0.2.0",
|
||||||
"remix-utils": "^7.6.0",
|
"remix-utils": "^7.6.0",
|
||||||
"shiki": "^1.9.1",
|
"shiki": "^1.9.1",
|
||||||
"unist-util-visit": "^5.0.0"
|
"unist-util-visit": "^5.0.0",
|
||||||
|
"web-speech-cognitive-services": "^8.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@blitz/eslint-plugin": "0.1.0",
|
"@blitz/eslint-plugin": "0.1.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user