是否可以使用Ionic实现类似"OK Google"的功能



我正在尝试构建像Alex或Google Home这样的应用程序,假设用户说"嘿MyApp",应打开麦克风,或者应自动调用与按钮关联的功能P>

我尝试了API.AI和离子TTS插件,但无法找到使用Ionic中语音命令启用本机功能的任何内容。

是的,您可以使用离子语音识别

进行
ionic cordova plugin add cordova-plugin-speechrecognition
npm install @ionic-native/speech-recognition

添加模块

然后运行

import { SpeechRecognition } from '@ionic-native/speech-recognition/ngx';
constructor(private speechRecognition: SpeechRecognition) { }
...

// Check feature available
this.speechRecognition.isRecognitionAvailable()
  .then((available: boolean) => console.log(available))
// Start the recognition process
this.speechRecognition.startListening(options)
  .subscribe(
    (matches: string[]) => console.log(matches),
    (onerror) => console.log('error:', onerror)
  )
// Stop the recognition process (iOS only)
this.speechRecognition.stopListening()
// Get the list of supported languages
this.speechRecognition.getSupportedLanguages()
  .then(
    (languages: string[]) => console.log(languages),
    (error) => console.log(error)
  )
// Check permission
this.speechRecognition.hasPermission()
  .then((hasPermission: boolean) => console.log(hasPermission))
// Request permissions
this.speechRecognition.requestPermission()
  .then(
    () => console.log('Granted'),
    () => console.log('Denied')
  )

在constructor&构建应用程序并安装。

然后说OK Google Open(您的应用程序名称(Google Assistant打开您的应用程序,语音识别小说将自动触发。

最新更新