Skip to content

Commit

Permalink
マイクボタンの活性切り替えがおかしくなってたので修正
Browse files Browse the repository at this point in the history
  • Loading branch information
tegnike committed Oct 13, 2024
1 parent 0a505d6 commit e3d3834
Showing 1 changed file with 8 additions and 3 deletions.
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

0 comments on commit e3d3834

Please sign in to comment.