javascript - 在 IOS 上反应语音到文本和文本到语音
问题描述
我对反应真的很陌生,我正在尝试使用反应创建一个语音到文本应用程序,我使用这个模块https://github.com/MikeyParton/react-speech-kit。这是我的语音识别功能
function SpeechRecognition() {
const [lang, setLang] = useState("en-US");
const [value, setValue] = useState("");
const [blocked, setBlocked] = useState(false);
const onEnd = () => {
// You could do something here after listening has finished
};
const onResult = (result) => {
setValue(result);
};
const changeLang = (event) => {
setLang(event.target.value);
};
const onError = (event) => {
if (event.error === "not-allowed") {
setBlocked(true);
}
};
const { listen, listening, stop, supported } = useSpeechRecognition({
onResult,
onEnd,
onError,
});
const toggle = listening
? stop
: () => {
setBlocked(false);
listen({ lang });
};
return (
<button disabled={blocked} type="button" onClick={toggle}>
{listening ? (
<FontAwesomeIcon icon={faMicrophoneSlash} />
) : (
<FontAwesomeIcon icon={faMicrophone} />
)}
</button>
);
}
它可以在任何浏览器上的 android 和 windows 上运行,但无论是 safari 还是 chrome,我都无法在 IOS 上运行。在我研究了 IOS webspeech API 之后,我发现了这篇文章http://iwearshorts.com/blog/ios-safari-partial-support-of-web-speech-api/但我不知道如何使用这行代码在我的代码上
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition || null;
https://bory-webspeech.netlify.app/我当前开发的演示
编辑
我改变这条线
const { listen, listening, stop, supported } = useSpeechRecognition({
至
const SpeechRecognition = useSpeechRecognition|| webkitSpeechRecognition || null;
`const { listen, listening, stop, supported } = SpeechRecognition ({`
但在IOS上它仍然无法正常工作
解决方案
推荐阅读
- java - 为什么在 docker 映像中创建的 .war 文件在浏览器中不起作用?(Java-Servlets、Tomcat、Docker)
- python - 如何使用 tkinter 和 excel 制作交互式 python 网格
- sql - 如何查看在给定时间段内传入和传出 sql server 的数据量?
- gnuplot - 平滑图的边界 - gnuplot
- asp.net - 替换 Scaffold-DbContext 中的连接字符串
- assembly - GNU ARM 汇编器将 mov 更改为添加?
- database - MongoDB Atlas 初始连接数和存储量很高
- ios - UICollectionViewCell 填充了错误的数据
- php - 在 Laravel 控制器中访问多维数组数据
- python - MATLAB 的 fread 与 Python 中的 skip 参数等效吗?