expo - Expo-speech 在某些 iOS 设备上不起作用
问题描述
我expo-speech
在我的应用程序中使用,但在某些 iOS 设备中没有读出文本。从让我的朋友测试它,我得到的结果是:
作品:
- iPhone X. 13.3.1
- iPhone 10。
- iPhone X. 13.3.1
- iPhone 8 加号。13.3.1
- iPhone 7+。13.1.2
不工作:
- iPhone Xs。13.3.1
- iPhone 8. 13.4.1
它也适用于我在本地开发时尝试过的每个 iOS 模拟器。
我创建了一个非常简单的 repo(下面的链接)来使用以下代码对其进行测试:
import React from 'react';
import * as Speech from "expo-speech";
import { StyleSheet, Text, View } from 'react-native';
export default function App() {
setInterval(()=>{
Speech.speak(`I am a test`);
}, 2000);
return (
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
https://snack.expo.io/@jamesweblondon/sound-test
使用 Expo 应用程序在 iPhone 8 13.4.1 上测试它也无法正常工作。
更新:事实证明,这是导致此问题的静默模式:https ://github.com/expo/expo/issues/8235
理想的解决方案是像 YouTube 等一样播放声音。
第二个最好的方法是在 iOS 中检测静音模式,这样我至少可以通知用户此功能不起作用以及如何修复它。
解决方案
由于静音模式,我在锻炼时间应用程序上遇到了同样的问题。
世博解决方案:
我们可以使用expo-av expo 库在静默模式下播放语音playsInSilentModeIOS: true
当其他声音处于播放模式时,在世博会文本到语音的工作。所以你可以附加空的声音
从这里下载空的声音
import React, { useEffect } from "react";
import * as Speech from "expo-speech";
import { StyleSheet, Text, View, Platform } from "react-native";
import { Audio } from "expo-av";
const soundObject = new Audio.Sound();
export default function App() {
useEffect(() => {
const enableSound = async () => {
if (Platform.OS === "ios") {
await Audio.setAudioModeAsync({
playsInSilentModeIOS: true,
});
await soundObject.loadAsync(require("./soundFile.mp3"));
await soundObject.playAsync();
}
setInterval(() => {
Speech.speak(`I am a test`);
}, 1000);
};
enableSound();
});
return (
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
React-Native 解决方案:
var Sound = require('react-native-sound');
Sound.setCategory('Playback'); // this will enable sound on silent mode
推荐阅读
- php - 如何在 laravel 5.4 中运行 .dll 文件
- openmdao - 组件 IO 是否有额外的内存限制
- mysql - 使用命令提示符安装 mysql 时出现问题,对于 django
- zurb-foundation - 在 Mac 上安装 Foundation-cli 的问题
- sql - 在 oracle 中快速执行什么语句,删除+插入或插入 ID 不在列表中。?
- apache-kafka-streams - 合并两个时间窗口的最佳模式是什么
- python - Matplotlib:从二进制数据填充
- html - 如何显示位置在通过 XMLHttpRequest 访问的 JSON 文件中的图像?
- java - Java Map computeIfAbsent 问题
- laravel - 如何在 Laravel 中直接访问数组或对象?