package com.tencent.mm.modelvoiceaddr;

import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.a.e;
import com.tencent.mm.audio.b.g;
import com.tencent.mm.modelvoiceaddr.a.c.a;
import com.tencent.mm.sdk.platformtools.ab;

class g$2 implements a {
    final /* synthetic */ g gbk;
    byte[] gbl;

    g$2(g gVar) {
        this.gbk = gVar;
    }

    public final void c(short[] sArr, int i) {
        AppMethodBeat.i(116707);
        if (sArr == null) {
            AppMethodBeat.o(116707);
            return;
        }
        int i2;
        if (this.gbl == null || this.gbl.length < i * 2) {
            this.gbl = new byte[(i * 2)];
        }
        for (i2 = 0; i2 < i; i2++) {
            this.gbl[i2 * 2] = (byte) (sArr[i2] & 255);
            this.gbl[(i2 * 2) + 1] = (byte) ((sArr[i2] & 65280) >> 8);
        }
        if (g.b(this.gbk) != null) {
            i2 = g.b(this.gbk).a(new g.a(this.gbl, i * 2), 0, true);
        } else {
            i2 = -1;
        }
        if (-1 == i2) {
            this.gbk.cG(4, -1);
            ab.e("MicroMsg.SceneVoiceInputAddr", "write to file failed");
            AppMethodBeat.o(116707);
            return;
        }
        g.a(this.gbk, i2 + g.h(this.gbk));
        if (!(g.i(this.gbk) || g.h(this.gbk) <= 200 || g.j(this.gbk))) {
            com.tencent.mm.kernel.g.RS().aa(new 1(this));
            g.l(this.gbk);
        }
        AppMethodBeat.o(116707);
    }

    public final void amu() {
        AppMethodBeat.i(116708);
        ab.i("MicroMsg.SceneVoiceInputAddr", "onSpeakToSilent");
        if (g.k(this.gbk) instanceof c) {
            try {
                ((c) g.k(this.gbk)).mw(e.cs(g.amt()));
                AppMethodBeat.o(116708);
                return;
            } catch (Exception e) {
                ab.printErrStackTrace("MicroMsg.SceneVoiceInputAddr", e, "cutShortSentence error", new Object[0]);
                this.gbk.cG(6, -1);
            }
        }
        AppMethodBeat.o(116708);
    }

    public final void amv() {
        AppMethodBeat.i(116709);
        ab.i("MicroMsg.SceneVoiceInputAddr", "onSilentToSpeak");
        if (g.k(this.gbk) instanceof c) {
            try {
                h hVar = ((c) g.k(this.gbk)).gay;
                ab.i("MicroMsg.ShortSentenceContainer", "createNewShortSentence");
                hVar.gbt.writeLock().lock();
                h.a aVar = new h.a(hVar);
                hVar.gbs.put(aVar.gbv, aVar);
                hVar.gbt.writeLock().unlock();
                if (g.b(this.gbk).Ff()) {
                    AppMethodBeat.o(116709);
                    return;
                }
                this.gbk.cG(5, -1);
                AppMethodBeat.o(116709);
                return;
            } catch (Exception e) {
                ab.printErrStackTrace("MicroMsg.SceneVoiceInputAddr", e, "createShortSentence error", new Object[0]);
                this.gbk.cG(6, -1);
            }
        }
        AppMethodBeat.o(116709);
    }

    public final void CV() {
        AppMethodBeat.i(116710);
        ab.i("MicroMsg.SceneVoiceInputAddr", "Silent enough to finish time %s", new Object[]{Long.valueOf(System.currentTimeMillis())});
        this.gbk.stop(false);
        AppMethodBeat.o(116710);
    }
}
