javascript - react JS : React Voice to Text Recognition

标签 javascript reactjs voice-recognition

我是 React JS 新手。我正在为输入框实现 React Voice to text 。我正在使用React Voice to Text我的工作插件。不知怎的,它对我不起作用。

还有其他库或插件对我有帮助吗?

我已经尝试过以下代码。

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-recognition 在 Chrome 上运行良好(因为它支持 Web Speech API)。我认为你没有正确使用它。

只需使用 create-react-app 创建新的 React 应用程序,并将 App.js 代码替换为以下代码。

import React, {Component } from 'react'
import SpeechRecognition from 'react-speech-recognition'

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>
    )
  }
}

export default SpeechRecognition(Dictaphone)

默认情况下,它开始直接监听。您可以通过提供 npm 文档中提到的选项来控制它。

const options = {
  autoStart: false
}

export default SpeechRecognition(options)(Dictaphone)

关于javascript - react JS : React Voice to Text Recognition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51543143/

相关文章:

javascript - 如何在 .bablerc 中使用的 package.json 中设置 env

javascript - 如何更新 knockoutjs 可观察数组项

javascript - IsInNet for ASP

reactjs - 错误: field type must be Input Type - cannot pass qlType into mutation

javascript - 从 React 中的 API 对象中提取数据

javascript - 在主函数内运行 2 个函数

reactjs - 使用 react-apollo,如何使用 TypeScript 在同一组件中定义 2 个突变?

c# - 如何在 C# 中将语法(规则)和听写(自由言论)与 SpeechRecognizer 混合使用

android - 录音时语音识别不工作

android - 印度 Android 语音识别