我正在尝试实现类似于Google ok搜索引擎的Web应用程序。
我在我的React Web应用程序中使用语音识别API。
我已经成功地实现了语音到文本。现在我想使用语音识别API在我的React Web应用程序中实现文本到语音,但我在他们的文档中找不到任何内容。
这是我的代码:
import React, { Component } from 'react';
import React, { PropTypes, Component } from 'react'
import SpeechRecognition from 'react-speech-recognition'
const propTypes = {
// Props injected by SpeechRecognition
transcript: PropTypes.string,
resetTranscript: PropTypes.func,
browserSupportsSpeechRecognition: PropTypes.bool
}
class Dictaphone extends Component {
render() {
const { transcript, resetTranscript, browserSupportsSpeechRecognition } = this.props
if (!browserSupportsSpeechRecognition) {
return null
}
return (
<div>
<button onClick={resetTranscript}>Reset</button>
<span>{transcript}</span>
</div>
)
}
}
Dictaphone.propTypes = propTypes
export default SpeechRecognition(Dictaphone)
您可以将react-speech npm用于文本到语音和语音到文本。
这是GitHub存储库:https://github.com/andrewkeig/react-speech