Closed alitele closed 7 months ago
Hi ! Can I see the code you used ?
`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.
Which platform ?
Take care of the availabilities you have set: const grammar = ['left', 'right', '[unk]'];
Vosk will only recognize "left", "right", or anything else this way
Which platform ?
For now I am testing on android
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 .
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 :)
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
Maybe try to use a larger model:
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.
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 !
I am using React native example but for every speech it return Result is: [unk] I tried small and large model both and result is same.