Можно ли реализовать функцию "ОК Google", используя Ionic - PullRequest
0 голосов
/ 25 мая 2019

Я пытаюсь создать приложение, такое как Alex или Google Home, предположим, что пользователь говорит «Привет, MyApp», микрофон должен быть открыт или функция, связанная с кнопкой, должна вызываться автоматически

Я пробовал плагины API.ai и Ionic TTS, но не смог найти ничего, чтобы включить нативные функции с помощью голосовых команд в Ionic.

1 Ответ

0 голосов
/ 25 мая 2019

да, вы можете сделать это, используя распознавание ионной речи это

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')
  )
...