You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

react-native-voice安卓端语音转文字功能失效求助

Android端react-native-voice录音无结果问题

问题概述

使用react-native-voice和expo-speech实现语音转文字+文字转语音功能,iOS端功能正常,但Android端启动录音后:

  • 会触发Voice.onSpeechStarts回调,但返回值为false
  • 录音结束后无任何识别结果返回
  • 录音完成后计划调用expo-speech朗读内容

环境信息

  • 依赖版本:
    "react": "18.2.0",
    "react-native": "0.71.0",
    "@react-native-voice/voice": "^3.2.4"
    
    已尝试过的@react-native-voice/voice版本:3.1.5、3.2.4
  • Android SDK版本:31

实现代码

export const Screen = () => {
  const [isRecording, setIsRecording] = useState(false);
  const [userMessage, setUserMessage] = useState('');

  useEffect(() => {
    Voice.onSpeechStart = onSpeechStartHandler;
    Voice.onSpeechEnd = onSpeechEndHandler;
    Voice.onSpeechResults = onSpeechResultsHandler;
    return () => {
      Voice.destroy().then(Voice.removeAllListeners);
    };
  }, []);

  const onSpeechStartHandler = e => {
    console.log('start handler=»', e);
  };

  const onSpeechEndHandler = e => {
    console.log('stop handler', e);
  };
  const onSpeechResultsHandler = e => {
    console.log('speech result handler', e);
    setUserMessage(e.value[0]);
  };

  const startRecording = async () => {
    setIsRecording(true);
    try {
      await Voice.start('en-US');
    } catch (e) {
      console.log('error -> ', e);
    }
  };

  const stopRecording = () => {
    setIsRecording(false);
    try {
      Voice.stop();
      console.log(userMessage);
    } catch (e) {
      console.log('error -> ', e);
    }
  };

  return (
    <View
      style={{
        alignContent: 'center',
        justifyContent: 'center',
        backgroundColor: 'black',
        flex: 1,
      }}>
      <Button
        title={isRecording ? 'Stop Speaking' : 'Start Speaking'}
        onPress={isRecording ? stopRecording : startRecording}
      />
    </View>
  );
};

错误情况

  • 运行代码后出现与语音服务相关的错误提示
  • 检查设备可用语音服务时,能看到系统列出的可用语音服务选项

内容的提问来源于stack exchange,提问作者Parzival

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 09:05:32