1import numpy as np
2import onnxruntime as ort
3import librosa
4
5LABELS = ["a", "i", "u", "e", "o", "N", "cons", "pau"]
6
7session = ort.InferenceSession("karin_vowel_v1_fp16.onnx")
8wav, _ = librosa.load("input.wav", sr=16000, mono=True)
9logits = session.run(None, {"wav": wav[None, :].astype(np.float32)})[0]
10frames = logits[0].argmax(axis=-1) # (T,) クラス index
11labels = [LABELS[i] for i in frames] # 20ms ごとのラベル列
1import * as ort from "onnxruntime-web";
2
3const LABELS = ["a", "i", "u", "e", "o", "N", "cons", "pau"];
4
5const session = await ort.InferenceSession.create("karin_vowel_v1_fp16.onnx");
6// wav: 事前に取得した Float32Array (16 kHz mono, [-1, 1])
7const tensor = new ort.Tensor("float32", wav, [1, wav.length]);
8const { logits } = await session.run({ wav: tensor });
9
10// logits.data は Float32Array (row-major, shape = [1, T, 8])
11const T = logits.dims[1];
12const frames = new Array(T);
13for (let t = 0; t < T; t++) {
14 let best = 0;
15 for (let c = 1; c < 8; c++) {
16 if (logits.data[t * 8 + c] > logits.data[t * 8 + best]) best = c;
17 }
18 frames[t] = best;
19}
20const labels = frames.map(i => LABELS[i]); // 20ms ごとのラベル列