我试图使文本语音在一个应用程序构建与世博会。
(编辑:这个 bug 的 repo 可以在这里找到:https://github.com/WrRaThY/expo-voice-test-1)
我正在运行所有最新版本的一切(从字面上开始玩这个今天,package.json 粘贴)。
"dependencies": {
"@nonsenselearning/voice": "^3.2.6",
"expo": "~46.0.9",
"expo-dev-client": "~1.2.1",
"expo-splash-screen": "~0.16.2",
"expo-status-bar": "~1.4.0",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-native": "0.69.4",
"react-native-web": "~0.18.7",
"expo-av": "~12.0.4",
"expo-file-system": "~14.1.0"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
您可能会对无意义的学习包感到惊讶,但我只是遵循this potential solution
我从这里遵循教程:
https://docs.expo.dev/development/getting-started/ https://github.com/react-native-voice/voice我还添加了以下内容到我的本地配置(因为我发现他们here和其他地方)
<package android:name="com.google.android.googlequicksearchbox"/>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
<intent>
<action android:name="android.speech.SpeechRecognizer" />
</intent>
没有结果。
相关代码:
Voice.onSpeechError = onSpeechError;
Voice.onSpeechResults = onSpeechResults;
Voice.addListener = () => {
console.log('addListener');
}
Voice.removeListeners = () => {
console.log('removeListeners');
}
Voice.getSpeechRecognitionServices().then(res => {
console.log('services', res);
})
function onSpeechResults(e) {
console.log('results', e);
setResults(e.value ?? []);
}
function onSpeechError(e) {
console.error(e);
}
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);
}
}
我得到关于服务没有被注册的错误,但意图配置使它消失。现在唯一被报告的是这样的:
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
但这很奇怪也没用.
我甚至按照这个要求以世博会友好的方式(https://docs.expo.dev/versions/v46.0.0/sdk/audio/)的权限,但也-没有结果。
和列表仍然是空的,我猜这是问题。这不是录制或录制权限的问题,因为我可以成功录制和播放音频,如下所示:
const { recording } = await Audio.Recording.createAsync(
Audio.RecordingOptionsPresets.HIGH_QUALITY
);
const { sound, status } = await recording.createNewLoadedSoundAsync(
{
isLooping: true,
volume: 1
},
);
await sound.playAsync();
这个 repo 有所有的代码:https://github.com/WrRaThY/expo-voice-test-1
结论是...它从一开始就起作用了。只是不在模拟器中...当我在真实设备上测试它时,它完美地工作了,所以我将它作为资源留在这里...
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(15条)