Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/components/messageInputContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const MessageInputContainer = ({ onChatProcessStart }: Props) => {
const audioBufferRef = useRef<Float32Array | null>(null)
const audioChunksRef = useRef<Blob[]>([])
const isListeningRef = useRef(false)
const [isListening, setIsListening] = useState(false)

useEffect(() => {
const SpeechRecognition =
Expand Down Expand Up @@ -68,7 +69,8 @@ export const MessageInputContainer = ({ onChatProcessStart }: Props) => {
} catch (error) {
console.error('Error starting recognition:', error)
}
isListeningRef.current = true // setIsListeningの代わりに直接更新
isListeningRef.current = true
setIsListening(true)

if (realtimeAPIMode) {
audioChunksRef.current = [] // 音声チャンクをリセット
Expand Down Expand Up @@ -135,7 +137,8 @@ export const MessageInputContainer = ({ onChatProcessStart }: Props) => {
const stopListening = useCallback(async () => {
if (recognition && isListeningRef.current) {
recognition.stop()
isListeningRef.current = false // setIsListeningの代わりに直接更新
isListeningRef.current = false
setIsListening(false)

if (realtimeAPIMode) {
if (mediaRecorder) {
Expand Down Expand Up @@ -189,6 +192,8 @@ export const MessageInputContainer = ({ onChatProcessStart }: Props) => {
if (isListeningRef.current) {
stopListening()
} else {
keyPressStartTime.current = Date.now()
isKeyboardTriggered.current = true
startListening()
}
}, [startListening, stopListening])
Expand Down Expand Up @@ -234,7 +239,7 @@ export const MessageInputContainer = ({ onChatProcessStart }: Props) => {
return (
<MessageInput
userMessage={userMessage}
isMicRecording={isListeningRef.current}
isMicRecording={isListening} // useState の値を使用
onChangeUserMessage={handleInputChange}
onClickMicButton={toggleListening}
onClickSendButton={handleSendMessage}
Expand Down