Giter Club home page Giter Club logo

Comments (11)

kingdcreations avatar kingdcreations commented on June 19, 2024

Hi ! Can I see the code you used ?

from react-native-vosk.

alitele avatar alitele commented on June 19, 2024
`import React, {useState, useEffect, useRef, useCallback} from 'react';

import {StyleSheet, View, Text, Button} from 'react-native';
import Vosk from 'react-native-vosk';

export default function App(): JSX.Element {
  const [ready, setReady] = useState<Boolean>(false);
  const [recognizing, setRecognizing] = useState<Boolean>(false);
  const [result, setResult] = useState<String | undefined>();

  const vosk = useRef(new Vosk()).current;

  const load = useCallback(() => {
    vosk
      .loadModel('model-en-en')
      .then(() => setReady(true))
      .catch((e: any) => console.log(e));
  }, [vosk]);

  const unload = useCallback(() => {
    vosk.unload();
    setReady(false);
  }, [vosk]);

  useEffect(() => {
    const resultEvent = vosk.onResult((res: {data: String}) => {
      console.log(res);

      console.log('A onResult event has been caught: ' + JSON.stringify(res));
    });

    return () => {
      resultEvent.remove();
    };
  }, [vosk]);

  //   const grammar = ['gauche', 'droite', '[unk]'];
  const grammar = ['left', 'right', '[unk]'];

  const record = () => {
    if (!ready) {
      return;
    }
    console.log('Starting recognition...');

    setRecognizing(true);
    vosk
      .start(grammar)
      .then((res: string) => {
        console.log('Result is: ' + res);
        setResult(res);
      })
      .catch((e: any) => {
        console.log('Error: ' + e);
      })
      .finally(() => {
        setRecognizing(false);
      });
  };

  return (
    <View style={styles.container}>
      <Button
        onPress={ready ? unload : load}
        title={ready ? 'Unload model' : 'Load model'}
        color="blue"
      />
      <Button
        onPress={record}
        title="Record"
        disabled={ready === false || recognizing === true}
        color="#841584"
      />
      <Text>Recognized word:</Text>
      <Text>{result}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  box: {
    width: 60,
    height: 60,
    marginVertical: 20,
  },
});
`

Hi @kingdcreations here is above my code , I have created a folder inside assets folder named model-en-en and pasted the model files into it.

from react-native-vosk.

riderodd avatar riderodd commented on June 19, 2024

Which platform ?

from react-native-vosk.

riderodd avatar riderodd commented on June 19, 2024

Take care of the availabilities you have set:
const grammar = ['left', 'right', '[unk]'];

Vosk will only recognize "left", "right", or anything else this way

from react-native-vosk.

alitele avatar alitele commented on June 19, 2024

Which platform ?

For now I am testing on android

from react-native-vosk.

alitele avatar alitele commented on June 19, 2024

Take care of the availabilities you have set: const grammar = ['left', 'right', '[unk]'];

Vosk will only recognize "left", "right", or anything else this way

Actually I didnt get what is grammer , could you please guide me ? and what should i add in there if i want to recognize english language .

from react-native-vosk.

kingdcreations avatar kingdcreations commented on June 19, 2024

Hi @alitele !

The grammar parameter is used to recognize only specified words/phrases for exemple:
in start(['left', 'right', '[unk]']) saying a word other than "left" or "right" returns "[unk]" as result, otherwise if you say "left", you ll get "left" as result.

To recognize anything just use start() without parameter !

Hope I could help you :)

from react-native-vosk.

alitele avatar alitele commented on June 19, 2024

Yes now it recognize but the accuracy is not good for example i spoke "pakistan america india" and it wrote "pakistan a map" is there any way to improve it ? Thanks a lot @kingdcreations

from react-native-vosk.

kingdcreations avatar kingdcreations commented on June 19, 2024

Maybe try to use a larger model:

https://alphacephei.com/vosk/models

from react-native-vosk.

alitele avatar alitele commented on June 19, 2024

ok if i download a bigger model then will it increase the app size too while uploading on store? secondly can the listener keeps listening continuously until we manually stop it ? as of now it listen for certain time period and then listener stops.

from react-native-vosk.

kingdcreations avatar kingdcreations commented on June 19, 2024

ok if i download a bigger model then will it increase the app size too while uploading on store? secondly can the listener keeps listening continuously until we manually stop it ? as of now it listen for certain time period and then listener stops.

Unfortunately yes !
For now it's not possible, but we are currently working on a v2 to handle that in #40
Stay in touch !

from react-native-vosk.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.