voice icon indicating copy to clipboard operation
voice copied to clipboard

Stop Recording After Small Pause

Open Muhammad-Nafees opened this issue 1 year ago • 15 comments

After a small pause(silence), react native voice sends a beep and stops recording speech on ANDROID. what is the issue PLEASE HELP

Muhammad-Nafees avatar Feb 16 '24 19:02 Muhammad-Nafees

+1

Need to continuously recognize as iOS.

chetanbhadarka avatar Feb 17 '24 05:02 chetanbhadarka

+1

Need to continuously recognize as iOS.

does it work offline ?

codding123vbf avatar Feb 20 '24 13:02 codding123vbf

+1 Need to continuously recognize as iOS.

does it work offline ?

didn't tested yet on offline and device.

chetanbhadarka avatar Feb 20 '24 14:02 chetanbhadarka

+1 Need to continuously recognize as iOS.

does it work offline ?

didn't tested yet on offline and device.

i tried but it didnt work offline....pease let me know if you find nay way to make it work offline as i need it urgently

codding123vbf avatar Feb 20 '24 14:02 codding123vbf

@chetanbhadarka how is it working on ios ? are there any issues like we are facing on android like stops recording and background noise etc

codding123vbf avatar Feb 20 '24 15:02 codding123vbf

@chetanbhadarka how is it working on ios ? are there any issues like we are facing on android like stops recording and background noise etc

I just tested in simulator for the features of this dependency, I can say for me it's working fine. I just test with example code of this repo.

chetanbhadarka avatar Feb 20 '24 15:02 chetanbhadarka

did anyone find any solution that why recording stops when i'm on silent?

Muhammad-Nafees avatar Feb 20 '24 16:02 Muhammad-Nafees

u can keep on calling the start recording funciton after every 4 seconds and add the new result wiht the previous result...i did the same and it works fine on ios for some reason lol

codding123vbf avatar Feb 21 '24 14:02 codding123vbf

u can keep on calling the start recording funciton after every 4 seconds and add the new result wiht the previous result...i did the same and it works fine on ios for some reason lol

I also tested your solution with android but not working properly as expected. As you mention here for iOS, but actually in iOS no need to do anything else. I just started and it's continuously listening and converting into Text. just have issue with Android only.

chetanbhadarka avatar Feb 21 '24 15:02 chetanbhadarka

+1

dbarner1 avatar Mar 08 '24 20:03 dbarner1

Is there any update on this? This really sucks

mraskar avatar Apr 04 '24 07:04 mraskar

I was looking for a fix for this issue and found one made by Nordsword3m on his fork of the project I haven't tested it yet

https://github.com/react-native-voice/voice/commit/55ed383d268b7c667995069debf3be540b342171

pedrol2b avatar Apr 04 '24 18:04 pedrol2b

+1

snippet avatar Apr 17 '24 07:04 snippet

I was looking for a fix for this issue and found one made by Nordsword3m on his fork of the project I haven't tested it yet

55ed383

Just tested this one on Android and no, it doesn't work.

Here's a component which does most of the job for me - use state to capture whether recording is active or not. If recording is still active but recognition has stopped, start it again.

import React, { useCallback, useEffect, useState } from "react"
import { StyleProp, TextStyle, View, ViewStyle } from "react-native"
import { Text, Button } from "app/components"
import RNVoice from "@react-native-voice/voice"

export interface VoiceProps {
  /**
   * An optional style override useful for padding & margin.
   */
  style?: StyleProp<ViewStyle>
  isRecording?: boolean
  setIsRecording?: (isRecording: boolean) => void
}

/**
 * Describe your component here
 */
export const Voice = function Voice(props: VoiceProps) {
  const { isRecording, setIsRecording } = props
  const [transcript, setTranscript] = useState([])
  const [partialTranscript, setPartialTranscript] = useState("")

  useEffect(() => {
    initVoice()
    // startListening()

    return () => {
      RNVoice.destroy().then(RNVoice.removeAllListeners)
    }
  }, [])

  useEffect(() => {
    console.log({ isRecording })
    if (isRecording) {
      initVoice()
      startListening()
    } else {
      stopListening()
    }
  }, [isRecording])

  const initVoice = () => {
    console.log("Init!")
    RNVoice.onSpeechResults = onSpeechResults
    RNVoice.onSpeechPartialResults = onSpeechPartialResults
    RNVoice.onTranscriptionResults = (e) => {
      console.log("TRANSCRIPTION", e)
    }
    RNVoice.onSpeechEnd = onSpeechEnd

    RNVoice.onTranscriptionEnd = () => {
      console.log("END")
    }
  }

  const onSpeechEnd = async () => {
    console.log("SPEECH END", isRecording)
    if (isRecording) {
      console.log("RESTARTING")
      await stopListening()
      await startListening()
    }
  }

  const startListening = async () => {
    try {
      await RNVoice.start("en-AU")
    } catch (e) {
      console.error(e)
    }
  }

  const stopListening = async () => {
    try {
      await RNVoice.stop()
    } catch (e) {
      console.error(e)
    }
  }

  const onSpeechResults = (e) => {
    const newTranscript = [...transcript, e.value[0]]
    setTranscript(newTranscript)
    console.log(newTranscript)
  }
  const onSpeechPartialResults = (e) => {
    console.log("PARTIAL", e)
    setPartialTranscript(e.value[0])
  }

  return (
    <View>
      <Text style={{ color: "white" }}>Partial: {partialTranscript}</Text>
      <Text style={{ color: "white" }}>Transcript: {transcript}</Text>
      <Text style={{ color: "white" }}>
        Status: {isRecording ? "Recording" : "Waiting"}
      </Text>
    </View>
  )
}

jvgeee avatar May 01 '24 02:05 jvgeee