Picovoice / picovoice

On-device voice assistant platform powered by deep learning
Apache License 2.0
561 stars 109 forks source link

Picovoice Documentation Issue (/docs/faq/general/) - Failed to initialize Porcupine: [Error: unexpected code: undefined, message: Cannot read property 'fromBuiltInKeywords' of null] #807

Closed TheFysionX closed 5 months ago

TheFysionX commented 5 months ago

I am getting this error:

Failed to initialize Porcupine: [Error: unexpected code: undefined, message: Cannot read property 'fromBuiltInKeywords' of null]

With this code :

import React, { useEffect, useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import { PorcupineManager, BuiltInKeywords } from '@picovoice/porcupine-react-native';

import PageDefault from '../../components/PageDefault'; import DarkTheme from '../../themes/DarkTheme';

const SettingsScreen = () => { const [isListening, setIsListening] = useState(false); const [detectedWord, setDetectedWord] = useState(""); const [porcupineManager, setPorcupineManager] = useState(null);

const wakeWordCallback = (keywordIndex) => { if (keywordIndex === BuiltInKeywords.Porcupine) { setDetectedWord('Porcupine'); } else if (keywordIndex === BuiltInKeywords.Bumblebee) { setDetectedWord('Bumblebee'); } // Add other keywords you are interested in };

useEffect(() => { const accessKey = "MY API KEY WAS HERE"; // Replace with your Picovoice AccessKey

const initPorcupine = async () => {
  try {
    const manager = await PorcupineManager.fromBuiltInKeywords(
      accessKey,
      [BuiltInKeywords.PORCUPINE, BuiltInKeywords.BUMBLEBEE],
      wakeWordCallback
    );
    setPorcupineManager(manager);
    await manager.start();
    setIsListening(true);
  } catch (error) {
    console.error('Failed to initialize Porcupine:', error);
  }
};

initPorcupine();

return () => {
  porcupineManager?.stop().then(() => {
    porcupineManager?.delete();
    setIsListening(false);
  });
};

}, []);

return ( <PageDefault title="Wake Word Test" src={require('../../assets/images/backgrounds/Menu2.webp')}>

{isListening ? ( Listening for wake word... ) : ( Not listening... )} {detectedWord !== "" && ( Detected: {detectedWord} )}
</PageDefault>

); };

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20, }, infoText: { fontSize: 24, fontFamily: DarkTheme.quadraFont, textAlign: 'center', color: DarkTheme.contrast, marginBottom: 10, }, detectedText: { fontSize: 24, fontFamily: DarkTheme.quadraFont, textAlign: 'center', color: DarkTheme.green, marginTop: 20, }, });

export default SettingsScreen;

I cannot find any explanation as to why this is occurring at all. I cannot use fromKeywordPaths either as that also returns the same error. The docs and the github give completely different ways to do the same thing and neither of them work at all. I have tried everything under the sun. There is no alternative for wake word detection for mobile and there is no solution to my error, I cannot find any other understand the error at all. What is going on and what do I do?

mrrostam commented 5 months ago

I am closing this issue because it seems to be confusing. Although the title suggests that there is an issue with our documentation (/doc/faq/general), the problem actually lies with one of our SDKs. Please open a new issue using our template so that I can assign it to the appropriate person.