Voice to text Feature Add expo

I am working on a voice to text product I complete my work at the expo but only one feature we added to the application is not available so kindly someone guides me that how we handle this problem I face kindly help me with this feature

Hi! I saw you linked this to my previous post. May I ask what exactly is the problem that you encountered? An attachment would help.

I use this library but it does not working in expo app or not in apk

Hi @awii

As I said on Canny, you should give us more info:

spm fm: Please create a post on forums.expo.dev with what you have tried, what error messages you got or what went wrong, what Expo SDK version you’re using, how you’re building the app, etc.

One thing to bear in mind: This will not work in the Expo Go app. You will need to build a custom development client with EAS Build and use that instead of Expo Go.

import React, { useState, useEffect } from "react";
import { Button, StyleSheet, Text, View } from "react-native";
import Voice, {
  SpeechResultsEvent,
  SpeechErrorEvent,
} from "@react-native-voice/voice";

export default function App() {
  const [results, setResults] = useState([] as string[]);
  const [isListening, setIsListening] = useState(false);

  useEffect(() => {
    function onSpeechResults(e: SpeechResultsEvent) {
      setResults(e.value ?? []);
    }
    function onSpeechError(e: SpeechErrorEvent) {
      console.error(e);
    }
    Voice.onSpeechError = onSpeechError;
    Voice.onSpeechResults = onSpeechResults;
    return function cleanup() {
      Voice.destroy().then(Voice.removeAllListeners);
    };
  }, []);

  async function toggleListening() {
    try {
      if (isListening) {
        await Voice.stop();
        setIsListening(false);
      } else {
        setResults([]);
        await Voice.start("en-US");
        setIsListening(true);
      }
    } catch (e) {
      console.error(e);
    }
  }

  return (
    <View style={styles.container}>
      <Text>Press the button and start speaking.</Text>
      <Button
        title={isListening ? "Stop Recognizing" : "Start Recognizing"}
        onPress={toggleListening}
      />
      <Text>Results:</Text>
      {results.map((result, index) => {
        return <Text key={`result-${index}`}>{result}</Text>;
      })}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF",
  },
});

I use this code in-app.TSX

And a use expo Version 44.0.0

and also use the plugin in the app.json

“plugins”: [

  [

    "@react-native-voice/voice",

    {

      "microphonePermission": "Allow $(PRODUCT_NAME) to access your microphone",

      "speechRecogntionPermission": "Allow $(PRODUCT_NAME) to securely recognize user speech"

    }

  ]

],

When we press the button Start Recording
We face errors in this type of
" null is not an object (evaluating ‘Voice.startSpeech’) "

Thanks for the extra info.

How are you building the app?

What, if anything, did you run on your PC, and what did you run on the phone or emulator/simulator when you got the error?

1 Like

when we run in pc or emulator so this type of error are show
" null is not an object (evaluating ‘Voice.startSpeech’) "

and when we create a build so he is not

sir please help me to save my product

What did you run? expo start? How did you run the app in the emulator?
I think you are trying to run your app in Expo Go in the emulator. @react-native-voice/voice will not work in Expo Go. If you want something similar to Expo Go while developing your app, build a development client.

So it works correctly when you create a build? So to answer my question about the build I assume you are running something like this? If not, how are you building the app?

eas build --platform android --profile preview

EDIT: I see that you posted something to Canny as well:

We face this type of error when we touch the start Button and we also create a build:android and he is not working in android phone

You cannot build with expo build:android when you want to use this library.
You have to build with eas build --platform android --profile ...

1 Like

Sir can you request Evan Bacon to create a demo video on this Feature

Please answer my questions. I do ask them for a reason:

  1. Did you build a development client?
  2. Did you build a standalone app?
  3. If so, how did you build them? (What commands did you run?)
  4. Did you get the error in Expo Go? (This is expected, because Expo Go does not contain the native code from @react-native-voice/voice.)
  5. If you built a development client, did you run expo start --dev-client on your PC and did you then run the development client on a device? If so, what was the result?
  6. If you built a standalone app using eas build, did you try running it on a device? If so, what happened?
1 Like

Sir Really Thankful to you for supporting me
last night I create an ease build and dev client so this library is working.
And Know today we check this eas build are working in ios ,
and also Sir I requested to you please add simplicity in this library like other libraries are working in the expo,
Sir, you are a Legend , Kindhearted,and a Greate Leader, GodBlessed You Sir

Hi @awii

I am glad you got it working.

Unfortunately there’s a tradeoff. The Expo team has to carefully consider what to add to the Expo SDK. One of the biggest complaints about Expo in the past was the size of the apps. If the Expo team adds every library like @react-native-voice/voice, it will grow even bigger!

They have written a short post about this here, although it was written before EAS was released. These days it’s possible to use EAS Build instead of ejecting:

expo.fyi/whats-in-the-sdk

By the way, I am just another Expo user. I am not an Expo team member.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.