我正在尝试构建一个类似Alex或Google Home的应用,假设用户说“ Hey MyApp”,应该打开麦克风或应该自动调用与该按钮关联的功能
我已经尝试过API.ai和Ionic TTS插件,但无法使用Ionic中的语音命令找到任何启用本机功能的功能。
答案 0 :(得分:0)
是的,您可以使用离子语音识别this
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')
)
答案 1 :(得分:0)
在构造函数中调用语音识别功能并构建应用程序并安装。
然后说“确定Google打开(您的应用名称)” Google助手打开您的应用程序,语音识别小说将自动触发。