Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop Recording After Small Pause #483

Open
Muhammad-Nafees opened this issue Feb 16, 2024 · 14 comments
Open

Stop Recording After Small Pause #483

Muhammad-Nafees opened this issue Feb 16, 2024 · 14 comments

Comments

@Muhammad-Nafees
Copy link

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

@chetanbhadarka
Copy link

+1

Need to continuously recognize as iOS.

@codding123vbf
Copy link

+1

Need to continuously recognize as iOS.

does it work offline ?

@chetanbhadarka
Copy link

+1
Need to continuously recognize as iOS.

does it work offline ?

didn't tested yet on offline and device.

@codding123vbf
Copy link

+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
Copy link

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

@chetanbhadarka
Copy link

@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.

@Muhammad-Nafees
Copy link
Author

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

@codding123vbf
Copy link

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

@chetanbhadarka
Copy link

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.

@dbarner1
Copy link

dbarner1 commented Mar 8, 2024

+1

@mraskar
Copy link

mraskar commented Apr 4, 2024

Is there any update on this? This really sucks

@pedrol2b
Copy link

pedrol2b commented Apr 4, 2024

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

@snippet
Copy link

snippet commented Apr 17, 2024

+1

@jvgeee
Copy link

jvgeee commented May 1, 2024

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>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants