2026-10-22 14:07:56 +09:00
|
|
|
"""Music in the room, for tests/asr_check.py --cases 4 (2026-10-22: soft music, nobody speaking, became "-끝-" -> goodbye):
|
|
|
|
|
music only (kind "noise": right is no wake word and no motion, nothing said), and speech over soft music (the speech
|
2026-10-22 14:11:47 +09:00
|
|
|
cases' own judgement). The music is made here: piano-like chords, bass, a melody and a hi-hat in four tempos
|
|
|
|
|
(never from data/songs/mine).
|
2026-10-22 14:07:56 +09:00
|
|
|
|
2026-10-22 14:11:47 +09:00
|
|
|
A case's "music" is "synth:<seed>:<seconds>"; "music_db" is how far the speech is above the music (rms).
|
2026-10-22 14:07:56 +09:00
|
|
|
"""
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
from tests.asr_cases import CASES as SPOKEN
|
|
|
|
|
|
|
|
|
|
RATE = 16000
|
|
|
|
|
MUSIC_DB = 6.0 # speech this much louder than the music (soft background music at a booth)
|
|
|
|
|
CASES = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def synth(seed, seconds):
|
|
|
|
|
"""Instrumental music: a I-V-vi-IV progression, decaying piano-like notes with harmonics, a bass, a melody
|
|
|
|
|
and a hi-hat on the beat. float32, peak 1."""
|
|
|
|
|
rng = np.random.default_rng(seed)
|
|
|
|
|
bpm = [72, 96, 118, 140][seed % 4]
|
|
|
|
|
beat = 60.0 / bpm
|
|
|
|
|
root = 48 + seed % 7 # MIDI note of the key
|
|
|
|
|
chords = [(0, 4, 7), (7, 11, 14), (9, 12, 16), (5, 9, 12)]
|
|
|
|
|
n = int(seconds * RATE)
|
|
|
|
|
out = np.zeros(n + 4 * RATE) # room for the last bar past the end
|
|
|
|
|
|
|
|
|
|
def note(midi, start, dur, gain, harmonics=4):
|
|
|
|
|
f = 440.0 * 2 ** ((midi - 69) / 12)
|
|
|
|
|
t = np.arange(int(dur * RATE)) / RATE
|
|
|
|
|
tone = sum(np.sin(2 * np.pi * f * k * t) / k ** 1.5 for k in range(1, harmonics + 1))
|
|
|
|
|
i = int(start * RATE)
|
|
|
|
|
if i >= len(out):
|
|
|
|
|
return
|
|
|
|
|
seg = tone * np.exp(-3.0 * t / dur) * gain
|
|
|
|
|
out[i:i + len(seg)] += seg[:len(out) - i]
|
|
|
|
|
|
|
|
|
|
t, bar = 0.0, 0
|
|
|
|
|
while t < seconds:
|
|
|
|
|
ch = chords[bar % 4]
|
|
|
|
|
for k in ch:
|
|
|
|
|
note(root + 12 + k, t, 4 * beat, 0.25)
|
|
|
|
|
note(root - 12 + ch[0], t, 2 * beat, 0.5, 2)
|
|
|
|
|
note(root - 12 + ch[0], t + 2 * beat, 2 * beat, 0.5, 2)
|
|
|
|
|
for b in range(4):
|
|
|
|
|
note(root + 24 + ch[rng.integers(0, 3)] + rng.choice([0, 12]), t + b * beat, beat, 0.2)
|
|
|
|
|
i = int((t + b * beat) * RATE)
|
|
|
|
|
hat = rng.standard_normal(int(0.03 * RATE)) * np.exp(-np.arange(int(0.03 * RATE)) / 80) * 0.15
|
|
|
|
|
out[i:i + len(hat)] += hat[:len(out) - i]
|
|
|
|
|
t, bar = t + 4 * beat, bar + 1
|
|
|
|
|
out = out[:n]
|
|
|
|
|
return (out / (np.abs(out).max() + 1e-9)).astype(np.float32)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def music(spec, seconds=None):
|
|
|
|
|
"""The case's music; `seconds` (under speech: the speech's length) instead of the spec's."""
|
2026-10-22 14:11:47 +09:00
|
|
|
_, seed, length = spec.split(":")
|
|
|
|
|
return synth(int(seed), seconds or float(length))
|
2026-10-22 14:07:56 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
for k in range(16):
|
|
|
|
|
CASES.append({"kind": "noise", "lang": "none", "text": f"(music {k})", "say": [],
|
|
|
|
|
"music": f"synth:{k}:{[1.5, 2.5, 4.0, 6.0][k % 4]}"})
|
|
|
|
|
R = random.Random(4)
|
|
|
|
|
for i, c in enumerate(R.sample(SPOKEN, 40)):
|
|
|
|
|
CASES.append({**c, "music": f"synth:{100 + i}:1.0", "music_db": MUSIC_DB})
|
|
|
|
|
for i, (lang, t) in enumerate([("en", "Sing a song."), ("en", "Let's do some music."), ("en", "Lumi, stop."),
|
|
|
|
|
("en", "Hi Lumi."), ("ko", "노래 불러 줘."), ("ko", "음악 틀어 줘."), ("ko", "루미야."),
|
|
|
|
|
("ko", "멈춰.")]):
|
|
|
|
|
kind = "wake" if "Lumi." in t or t == "루미야." else "command"
|
|
|
|
|
CASES.append({"kind": kind, "lang": lang, "text": t, "say": [(lang, t)], "music": f"synth:{200 + i}:1.0",
|
|
|
|
|
"music_db": MUSIC_DB})
|