"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const speech_1 = require("../../../../../api/speech");
const Holder_1 = require("../../../../../Class/Holder");
const _ids_1 = require("../../../../_ids");
class SpeechToText extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['opt'],
            fo: [],
            i: ['start', 'stop'],
            o: ['text'],
        }, {}, system, _ids_1.ID_SPEECH_TO_TEXT);
    }
    f({ opt }, done, fail) {
        const recorder = new speech_1.SpeechRecorder(this.__system, opt);
        this._recorder = recorder;
        this._recorder.addListener('transcript', (text) => {
            this._output.text.push(text);
        });
        this._recorder.addListener('err', (err) => {
            fail(err);
        });
    }
    d() {
        if (this._recorder) {
            this._recorder.stop();
            this._recorder = undefined;
        }
    }
    onIterDataInputData(name, data) {
        super.onIterDataInputData(name, data);
        if (name === 'stop') {
            if (this._recorder) {
                try {
                    this._recorder.stop();
                }
                catch (err) {
                    //
                }
            }
            this._backward('stop');
        }
        else if (name === 'start') {
            if (this._recorder) {
                try {
                    this._recorder.start();
                }
                catch (err) {
                    //
                }
            }
            this._backward('start');
        }
    }
}
exports.default = SpeechToText;
//# sourceMappingURL=index.js.map