【问题标题】:ionic 4 speech recognition离子4语音识别
【发布时间】:2020-03-08 14:58:52
【问题描述】:

我正在尝试使用Speech-recognition,但我不断收到错误,这是我的页面

   import {Component} from '@angular/core';
import {SpeechRecognition} from '@ionic-native/speech-recognition';

@Component({
    selector: 'app-home',
    templateUrl: 'home.page.html',
    styleUrls: ['home.page.scss'],
})
export class HomePage {

    constructor(private speechRecognition: SpeechRecognition) {
        this.speechRecognition.requestPermission()
            .then(
                () => console.log('Granted'),
                () => console.log('Denied')
            );
    }

    record() {
        const options = {
            language: 'da-DK',
            prompt: '',      // Android only
            showPopup: true,  // Android only
            showPartial: false
        };
        this.speechRecognition.startListening(options)
            .subscribe(
                (matches: Array<string>) => console.log(matches),
                (onerror) => console.log('error:', onerror)
            );
    }

}

这样我得到以下错误:

    RROR in src/app/home/home.page.ts(12,32): error TS2339: Property 'requestPermission' does not exist on type 'SpeechRecognition'.
[ng]     src/app/home/home.page.ts(26,32): error TS2339: Property 'startListening' does not exist on type 'SpeechRecognition'.

我正在使用 ionic 4

【问题讨论】:

  • 你用的是ionic 3还是ionic 4?
  • 嘿,克里斯,我正在使用 ionic 4

标签: javascript angular ionic-framework


【解决方案1】:

在导入时使用 ngx 从 '@ionic-native/speech-recognition/ngx' 导入 { SpeechRecognition };

也许你也应该作为提供者导入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    相关资源
    最近更新 更多