package ost import "testing" func TestParseLattice(t *testing.T) { raw := map[string]any{ "lattice": []any{ map[string]any{ "spk": "段落-0", "json_1best": map[string]any{ "st": map[string]any{ "bg": "0", "ed": "470", "rt": []any{ map[string]any{ "ws": []any{ map[string]any{"cw": []any{map[string]any{"w": "听说", "wp": "n"}}}, map[string]any{"cw": []any{map[string]any{"w": "。", "wp": "p"}}}, map[string]any{"cw": []any{map[string]any{"w": "", "wp": "g"}}}, }, }, }, }, }, }, }, } segs := parseLattice(raw) if len(segs) != 1 { t.Fatalf("segs=%d", len(segs)) } if segs[0].Text != "听说。" || segs[0].StartMs != 0 || segs[0].EndMs != 470 || segs[0].Speaker != "段落-0" { t.Fatalf("%+v", segs[0]) } } func TestApplySpeaker(t *testing.T) { msft := map[string]any{} applySpeaker(msft, "iflyrec_voice_mul_cbm_msft_24h", true, "raw") if msft["spkdia"] != 1 || msft["speaker_num"] != msftSpeakerCap { t.Fatalf("msft %+v", msft) } if _, ok := msft["vspp_on"]; ok { t.Fatal("微软通道不该带 vspp_on") } off := map[string]any{} applySpeaker(off, "iflyrec_voice_mul_cbm_msft_24h", false, "raw") if len(off) != 0 { t.Fatalf("off %+v", off) } self := map[string]any{} applySpeaker(self, "iflyrec_voice_cn_10m_ed", true, "raw") if self["vspp_on"] != 1 || self["speaker_num"] != 0 { t.Fatalf("self %+v", self) } mp3 := map[string]any{} applySpeaker(mp3, "iflyrec_voice_cn_10m_ed", true, "lame") if len(mp3) != 0 { t.Fatalf("mp3 %+v", mp3) } } func TestAudioEncoding(t *testing.T) { enc, _ := audioEncoding("https://oss.example.com/a/b.MP3?x=1") if enc != "lame" { t.Fatal(enc) } enc, format := audioEncoding("https://oss.example.com/a/b.wav") if enc != "raw" || format != "audio/L16;rate=16000" { t.Fatal(enc, format) } }