Skip to content

the ultimate vocal synthesizer - sing, speak, beatbox, and more

Rust

Vector display, phase 3: Speak

Jameson Hodgef10b49cd0df7
diff --git a/src/ui/App.tsx b/src/ui/App.tsx
index 53bced5..ed7ac56 100644
--- a/src/ui/App.tsx
+++ b/src/ui/App.tsx
@@ -10,7 +10,7 @@ import { VoiceControls, VoiceToggles } from "./components/VoiceControls.tsx";
import { Keys } from "./components/Keys.tsx";
import { Segmented, Toggle } from "./components/Controls.tsx";
import { Screen } from "./components/Screen.tsx";
-import { SpeakPanel } from "./components/SpeakPanel.tsx";
+import { SpeakRight, speechInfo, speechSlots } from "./components/SpeakPanel.tsx";
import { BestiaryPanel } from "./components/BestiaryPanel.tsx";
import { CreatureView } from "./components/CreatureView.tsx";
import { Spectrogram } from "./components/Spectrogram.tsx";
@@ -157,7 +157,7 @@ function LeftScreen() {
label={bestiary ? "Live creature airway" : "Live vocal tract"}
tools={<ViewToggles />}
>
- {bestiary ? <CreatureView /> : <AnatomyView />}
+ {bestiary ? <CreatureView /> : mode === "speak" ? <AnatomyView slots={speechSlots} info={speechInfo} /> : <AnatomyView />}
{mode === "beatbox" && <BeatOverlay />}
<StartPrompt />
</Screen>
@@ -212,7 +212,6 @@ function LegacyRight() {
function Deck() {
const mode = useStore((s) => s.mode);
- if (mode === "speak") return <SpeakPanel />;
if (mode === "sing") return <SingPanel />;
if (mode === "bestiary") return <BestiaryPanel />;
if (mode === "beatbox") return <BeatboxPanel />;
@@ -226,7 +225,7 @@ export function App() {
<TopBar />
<main className={`wall wall-${mode}`}>
<LeftScreen />
- {mode === "play" ? <PlayRight /> : <LegacyRight />}
+ {mode === "play" ? <PlayRight /> : mode === "speak" ? <SpeakRight /> : <LegacyRight />}
</main>
<Deck />
</div>
diff --git a/src/ui/components/AnatomyView.tsx b/src/ui/components/AnatomyView.tsx
index 655e8fb..79eecb2 100644
--- a/src/ui/components/AnatomyView.tsx
+++ b/src/ui/components/AnatomyView.tsx
@@ -11,6 +11,15 @@ import type { TelemetryMessage } from "../../worklet/protocol.ts";
/** What the four readouts under the chin show; a mode can pass its own. */
export type SlotsFn = (m: VoiceModel, a: HumanArtic, f: HumanFrame, formants: number[], tele: TelemetryMessage | null) => Slot[];
+/** The small lines under the formants; a mode can pass its own. */
+export type InfoFn = (m: VoiceModel, f: HumanFrame, tele: TelemetryMessage | null) => string[];
+
+/** the tract's length and mouth opening, then the live pitch and lungs */
+export const tractInfo: InfoFn = (_m, f, tele) => {
+ const info = [`Tract ${f.length.toFixed(1)} cm`, `Mouth ${f.lipArea.toFixed(1)} cm²`];
+ if (tele) info.push(`F0 ${tele.t.f0.toFixed(1)} Hz`, `Lungs ${tele.t.pLung.toFixed(1)} cmH₂O`);
+ return info;
+};
/** the calibrated vowel nearest to (F1, F2), same metric as the vowel map */
export function nearestVowel(m: VoiceModel, F1: number, F2: number): string {
@@ -33,9 +42,11 @@ export const articulatorSlots: SlotsFn = (m, a, f, formants) => [
f.velumPort > 0.02 ? { label: "Soft palate", value: f.velumPort.toFixed(2), unit: "cm²", color: V.white } : { label: "Soft palate", value: "Shut", color: V.white },
];
-export function AnatomyView(props: { slots?: SlotsFn }) {
+export function AnatomyView(props: { slots?: SlotsFn; info?: InfoFn }) {
const slotsRef = useRef<SlotsFn>(props.slots ?? articulatorSlots);
slotsRef.current = props.slots ?? articulatorSlots;
+ const infoRef = useRef<InfoFn>(props.info ?? tractInfo);
+ infoRef.current = props.info ?? tractInfo;
const canvasRef = useRef<HTMLCanvasElement>(null);
const wrapRef = useRef<HTMLDivElement>(null);
const model = useModel();
@@ -79,8 +90,7 @@ export function AnatomyView(props: { slots?: SlotsFn }) {
if (m && w > 0 && h > 0) {
const f = m.frame(a);
if (++fTick % 4 === 0 || formants.length === 0) formants = m.transfer(a).formants;
- const info = [`Tract ${f.length.toFixed(1)} cm`, `Mouth ${f.lipArea.toFixed(1)} cm²`];
- if (tele) info.push(`F0 ${tele.t.f0.toFixed(1)} Hz`, `Lungs ${tele.t.pLung.toFixed(1)} cmH₂O`);
+ const info = infoRef.current(m, f, tele);
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = "#000";
diff --git a/src/ui/components/ScoreView.tsx b/src/ui/components/ScoreView.tsx
index d5b3539..4971442 100644
--- a/src/ui/components/ScoreView.tsx
+++ b/src/ui/components/ScoreView.tsx
@@ -1,16 +1,18 @@
import { useEffect, useRef } from "react";
-import { useCanvasLoop, font } from "../useCanvas.ts";
+import { usePhosphor } from "../usePhosphor.ts";
import { engine } from "../../audio/AudioEngine.ts";
import { currentPlan, onPlan, type SpokenPlan } from "../speech.ts";
import { activation, type Gesture } from "../../wasm/engine.ts";
-import { C } from "../colors.ts";
+import { V } from "../colors.ts";
+import { beam, beamPts, label, seg, type Pt } from "../render/vector.ts";
-const ROWS: { name: string; keys: string[] }[] = [
- { name: "Lips", keys: ["lipAp", "lipProt", "lipWidth", "labiodental"] },
- { name: "Tongue tip", keys: ["ttX", "ttY", "ttCurl", "lateral"] },
- { name: "Tongue body", keys: ["tbX", "tbY", "root"] },
- { name: "Soft palate", keys: ["velum"] },
- { name: "Glottis", keys: ["abduction", "closure"] },
+/** rows of the score, coloured like the articulators on the face (lips pink, tongue green, soft palate white, glottis amber) */
+const ROWS: { name: string; keys: string[]; color: string }[] = [
+ { name: "Lips", keys: ["lipAp", "lipProt", "lipWidth", "labiodental"], color: V.pink },
+ { name: "Tongue tip", keys: ["ttX", "ttY", "ttCurl", "lateral"], color: V.green },
+ { name: "Tongue body", keys: ["tbX", "tbY", "root"], color: V.green },
+ { name: "Soft palate", keys: ["velum"], color: V.white },
+ { name: "Glottis", keys: ["abduction", "closure"], color: V.amber },
];
function rowOf(g: Gesture): number {
@@ -23,37 +25,31 @@ function rowOf(g: Gesture): number {
return -1;
}
-/** Gestural score of the current utterance (Articulatory Phonology), with live playhead. */
+/** current time on the plan's clock (s), or -1 when nothing is playing */
+export function planNow(sp: SpokenPlan | null): number {
+ const tele = engine.latest;
+ return sp && sp.offset !== null && tele ? tele.t.clock - sp.offset : -1;
+}
+
+/** Gestural score of the current utterance (Articulatory Phonology), with a live playhead. */
export function ScoreView() {
const planRef = useRef<SpokenPlan | null>(currentPlan());
useEffect(() => onPlan((p) => (planRef.current = p)), []);
- const ref = useCanvasLoop(({ ctx, w, h }) => {
- ctx.clearRect(0, 0, w, h);
+ const ref = usePhosphor(({ ctx, w, h }) => {
const sp = planRef.current;
- const left = 92, right = w - 8, top = 8, bottom = h - 30;
+ const left = 104, right = w - 14, top = 18, bottom = h - 26;
const rowH = (bottom - top) / (ROWS.length + 1);
- ctx.font = font(12);
- ctx.fillStyle = C.textDim;
- ROWS.forEach((r, i) => ctx.fillText(r.name, 4, top + rowH * (i + 0.62)));
- ctx.fillText("Pitch", 4, top + rowH * (ROWS.length + 0.62));
- ctx.strokeStyle = "rgba(255,255,255,0.06)";
- for (let i = 0; i <= ROWS.length + 1; i++) {
- ctx.beginPath();
- ctx.moveTo(left, top + rowH * i);
- ctx.lineTo(right, top + rowH * i);
- ctx.stroke();
- }
+ ROWS.forEach((r, i) => label(ctx, r.name.toUpperCase(), 14, top + rowH * (i + 0.62), { size: 9, color: r.color, ls: 0.16, alpha: 0.85 }));
+ label(ctx, "PITCH", 14, top + rowH * (ROWS.length + 0.62), { size: 9, color: V.amber, ls: 0.16, alpha: 0.85 });
+ for (let i = 1; i <= ROWS.length + 1; i++) seg(ctx, left, top + rowH * i, right, top + rowH * i, V.frame, 1);
if (!sp) {
- ctx.fillStyle = C.textDim;
- ctx.fillText("Speak something to see its gestures: which articulator moves, when, and how they overlap.", left, h / 2);
+ label(ctx, "SPEAK SOMETHING TO SEE ITS GESTURES: WHICH ARTICULATOR MOVES, WHEN, AND HOW THEY OVERLAP.", left, top + rowH * 2.6, { size: 10, color: V.blueMid, ls: 0.12 });
return;
}
const plan = sp.plan;
const T0 = -0.05, T1 = plan.end + 0.15;
const X = (t: number) => left + ((t - T0) / (T1 - T0)) * (right - left);
- const tele = engine.latest;
- const now = sp.offset !== null && tele ? tele.t.clock - sp.offset : -1;
- // gestures
+ const now = planNow(sp);
const f0s: { t: number; f: number }[] = [];
for (const g of plan.gestures) {
if (g.targets.f0 !== undefined) {
@@ -62,66 +58,54 @@ export function ScoreView() {
}
const r = rowOf(g);
if (r < 0) continue;
- const x0 = X(g.t0 - g.rampIn), x1 = X(g.t1 + g.rampOut);
- const xa = X(g.t0), xb = X(g.t1);
- const y = top + rowH * r + rowH * 0.18, hh = rowH * 0.64;
+ const yb = top + rowH * (r + 1) - 3, yt = top + rowH * r + 7;
+ const x0 = X(g.t0 - g.rampIn), xa = X(g.t0), xb = X(g.t1), x1 = X(g.t1 + g.rampOut);
const isVowel = r === 2 && Object.keys(g.targets).length > 4;
- const active = now >= g.t0 - g.rampIn && now <= g.t1 + g.rampOut ? activation(g, now) : 0;
- const base = isVowel ? "154,163,168" : "242,207,91";
- const grad = ctx.createLinearGradient(x0, 0, x1, 0);
- const a = isVowel ? 0.28 : 0.5;
- grad.addColorStop(0, `rgba(${base},0)`);
- grad.addColorStop(Math.max(0, Math.min(1, (xa - x0) / Math.max(1, x1 - x0))), `rgba(${base},${a})`);
- grad.addColorStop(Math.max(0, Math.min(1, (xb - x0) / Math.max(1, x1 - x0))), `rgba(${base},${a})`);
- grad.addColorStop(1, `rgba(${base},0)`);
- ctx.fillStyle = grad;
- ctx.beginPath();
- ctx.roundRect(x0, y, Math.max(2, x1 - x0), hh, 4);
- ctx.fill();
- if (active > 0.05) {
- ctx.strokeStyle = `rgba(${base},${0.5 + 0.5 * active})`;
- ctx.lineWidth = 1.5;
- ctx.stroke();
- }
- if (g.label && (xb - xa > 12 || !isVowel)) {
- ctx.fillStyle = isVowel ? "rgba(232,234,235,0.85)" : "#1d1a10";
- ctx.font = font(12, 600);
- const lbl = g.label === "aspiration" || g.label === "voiceless" ? "open" : g.label === "velum" ? "lowered" : g.label;
- ctx.fillText(lbl, Math.max(x0 + 3, xa + 2), y + hh * 0.7);
+ const act = now >= g.t0 - g.rampIn && now <= g.t1 + g.rampOut ? activation(g, now) : 0;
+ // a gesture is a trapezoid: ramp in, plateau, ramp out
+ const p = new Path2D();
+ p.moveTo(x0, yb);
+ p.lineTo(xa, yt);
+ p.lineTo(xb, yt);
+ p.lineTo(x1, yb);
+ beam(ctx, p, ROWS[r].color, act > 0.05 ? 1.5 : 1.1, { alpha: act > 0.05 ? 0.6 + 0.4 * act : isVowel ? 0.42 : 0.75, hot: act > 0.5 });
+ if (g.label && xb - xa > 10) {
+ const lbl = g.label === "aspiration" || g.label === "voiceless" ? "OPEN" : g.label === "velum" ? "LOWERED" : g.label;
+ label(ctx, lbl, (xa + xb) / 2, yb - 4, { size: 10, color: ROWS[r].color, align: "center", ls: 0.08, alpha: isVowel && act < 0.05 ? 0.6 : 1 });
}
}
- // pitch contour
+ // the pitch contour
if (f0s.length) {
- f0s.sort((p, q) => p.t - q.t);
- const fmin = Math.min(...f0s.map((p) => p.f)) * 0.9, fmax = Math.max(...f0s.map((p) => p.f)) * 1.1;
- const yb = top + rowH * ROWS.length + rowH * 0.9, ya = top + rowH * ROWS.length + rowH * 0.1;
- ctx.beginPath();
- f0s.forEach((p, i) => {
- const x = X(p.t), y = yb - ((p.f - fmin) / Math.max(1, fmax - fmin)) * (yb - ya);
- if (i) ctx.lineTo(x, y);
- else ctx.moveTo(x, y);
- });
- ctx.strokeStyle = "rgba(232,234,235,0.8)";
- ctx.lineWidth = 1.5;
- ctx.stroke();
+ f0s.sort((a, b) => a.t - b.t);
+ const fmin = Math.min(...f0s.map((q) => q.f)) * 0.92, fmax = Math.max(...f0s.map((q) => q.f)) * 1.08;
+ const yb = top + rowH * (ROWS.length + 1) - 4, ya = top + rowH * ROWS.length + 6;
+ const pts: Pt[] = f0s.map((q) => [X(q.t), yb - ((q.f - fmin) / Math.max(1, fmax - fmin)) * (yb - ya)]);
+ beamPts(ctx, pts, V.amber, 1.3);
+ const lastP = pts[pts.length - 1];
+ label(ctx, `${Math.round(f0s[f0s.length - 1].f)} HZ`, lastP[0] + 6, lastP[1] + 3, { size: 9, color: V.amber, ls: 0.1 });
}
- // segment labels along the bottom
- ctx.font = font(13, 500);
- ctx.fillStyle = "rgba(232,234,235,0.9)";
+ // segments along the bottom
+ let lastRight = -Infinity;
for (const s of plan.segments) {
const x = X((s.t0 + s.t1) / 2);
- const tw = ctx.measureText(s.ipa).width;
- ctx.fillText(s.ipa, x - tw / 2, h - 10);
+ if (x - 6 < lastRight) continue;
+ lastRight = x + 6;
+ const on = now >= s.t0 && now < s.t1;
+ seg(ctx, X(s.t0), bottom + 2, X(s.t0), bottom + 6, V.blueDim, 1);
+ label(ctx, s.ipa, x, h - 8, { size: 12, color: on ? V.white : V.blue, align: "center", ls: 0 });
}
// playhead
if (now >= T0 && now <= T1) {
- ctx.strokeStyle = C.caliper;
- ctx.lineWidth = 1.5;
- ctx.beginPath();
- ctx.moveTo(X(now), top);
- ctx.lineTo(X(now), h - 24);
- ctx.stroke();
+ const x = X(now);
+ seg(ctx, x, top - 4, x, bottom, V.white, 1.2, { hot: true });
+ const tri = new Path2D();
+ tri.moveTo(x - 5, top - 10);
+ tri.lineTo(x + 5, top - 10);
+ tri.lineTo(x, top - 3);
+ tri.closePath();
+ beam(ctx, tri, V.white, 1.1);
+ label(ctx, `${Math.max(0, now).toFixed(2)} S`, x + 8, top - 4, { size: 9, color: V.white, ls: 0.12, alpha: 0.8 });
}
});
- return <canvas ref={ref} className="score-canvas" aria-label="Gestural score of the current utterance" role="img" />;
+ return <canvas ref={ref} className="score-canvas" aria-label="Gestural score of the current utterance: which articulator moves, when, and how they overlap" role="img" />;
}
diff --git a/src/ui/components/SpeakPanel.tsx b/src/ui/components/SpeakPanel.tsx
index e8b648a..9b929de 100644
--- a/src/ui/components/SpeakPanel.tsx
+++ b/src/ui/components/SpeakPanel.tsx
@@ -3,12 +3,21 @@ import { useStore } from "../store.ts";
import { speakText, speakPhrases, stopSpeaking, onPlan, currentPlan } from "../speech.ts";
import { tokenizeIpa } from "../../wasm/engine.ts";
import { Slider, Toggle } from "./Controls.tsx";
-import { ScoreView } from "./ScoreView.tsx";
+import { Chip, Screen } from "./Screen.tsx";
+import { ScoreView, planNow } from "./ScoreView.tsx";
+import { TubeView } from "./TubeView.tsx";
+import { Stroboscope } from "./Stroboscope.tsx";
+import type { InfoFn, SlotsFn } from "./AnatomyView.tsx";
+import { V } from "../colors.ts";
+import { engine } from "../../audio/AudioEngine.ts";
const EXAMPLES = ["Hello. Can you hear me?", "She sells sea shells by the sea shore.", "Every sound here is air moving through a throat.", "The quick brown fox jumps over the lazy dog."];
// IPA pulmonic consonant chart (rows = manner, columns = place); empty cells are null
const PLACES = ["Bilabial", "Labiodental", "Dental", "Alveolar", "Postalveolar", "Retroflex", "Palatal", "Velar", "Uvular", "Pharyngeal", "Glottal"];
+/** short headings for the chart's narrow columns (the full names are the cells' titles) */
+const PLACE_SHORT = ["Bilab", "Labdent", "Dental", "Alveol", "Postalv", "Retrofl", "Palatal", "Velar", "Uvular", "Pharyn", "Glottal"];
+const MANNER_SHORT: Record<string, string> = { "Lateral fricative": "Lat fric", Approximant: "Approx" };
const CHART: [string, (string | null)[][]][] = [
["Plosive", [["p", "b"], [null, null], [null, null], ["t", "d"], [null, null], ["ʈ", "ɖ"], ["c", "ɟ"], ["k", "g"], ["q", "ɢ"], [null, null], ["ʔ", null]]],
["Nasal", [[null, "m"], [null, "ɱ"], [null, null], [null, "n"], [null, null], [null, "ɳ"], [null, "ɲ"], [null, "ŋ"], [null, "ɴ"], [null, null], [null, null]]],
@@ -20,7 +29,87 @@ const CHART: [string, (string | null)[][]][] = [
["Lateral", [[null, null], [null, null], [null, null], [null, "l"], [null, null], [null, "ɭ"], [null, "ʎ"], [null, null], [null, null], [null, null], [null, null]]],
];
-export function SpeakPanel() {
+/** the segment sounding now in the current utterance */
+function soundingSegment(): string | null {
+ const sp = currentPlan();
+ const now = planNow(sp);
+ if (!sp || now < 0) return null;
+ return sp.plan.segments.find((s) => now >= s.t0 && now < s.t1)?.ipa ?? null;
+}
+
+/** Speak mode's readouts under the chin: the sound being made, jaw, lip shape, soft palate */
+export const speechSlots: SlotsFn = (_m, a, f) => {
+ const sound = soundingSegment();
+ const lips = a.lipAp < 0.05 ? "Closed" : a.lipWidth < 0.55 ? "Round" : a.lipAp > 1.3 ? "Open" : "Spread";
+ return [
+ sound ? { label: "Sound", value: sound, color: V.green, ipa: true } : { label: "Sound", value: "-", color: V.green },
+ { label: "Jaw", value: a.jaw.toFixed(1), unit: "cm", color: V.red },
+ { label: "Lips", value: lips, color: V.pink },
+ { label: "Soft palate", value: f.velumPort > 0.02 ? "Open" : "Shut", color: V.white },
+ ];
+};
+
+/** what the voice is doing: voiced or not, where the noise is, the lungs */
+export const speechInfo: InfoFn = (m, _f, tele) => {
+ if (!tele) return [];
+ const t = tele.t;
+ const out = [t.voicing > 0.3 ? `Voiced ${t.f0.toFixed(0)} Hz` : "Voiceless"];
+ if (t.noiseLevel > 1 && t.noiseNode >= 0) {
+ const s = m.branchS(t.noiseNode, t.phLen, t.orLen);
+ if (s >= 0) out.push(`Noise at ${s.toFixed(1)} cm`);
+ }
+ out.push(`Lungs ${t.pLung.toFixed(1)} cmH₂O`);
+ return out;
+};
+
+function ConsonantChart(props: { onPad: (c: string) => void }) {
+ const [now, setNow] = useState<string | null>(null);
+ useEffect(() => {
+ const id = setInterval(() => setNow(engine.latest ? soundingSegment() : null), 60);
+ return () => clearInterval(id);
+ }, []);
+ return (
+ <div className="chart-scroll">
+ <table className="ipa-chart">
+ <thead>
+ <tr>
+ <th />
+ {PLACES.map((p, i) => (
+ <th key={p} scope="col" title={p} aria-label={p}>
+ {PLACE_SHORT[i]}
+ </th>
+ ))}
+ </tr>
+ </thead>
+ <tbody>
+ {CHART.map(([manner, cells]) => (
+ <tr key={manner}>
+ <th scope="row" title={manner} aria-label={manner}>
+ {MANNER_SHORT[manner] ?? manner}
+ </th>
+ {cells.map((pair, i) => (
+ <td key={i}>
+ {pair.map((sym, j) =>
+ sym ? (
+ <button key={j} className={`ipa${sym === now ? " now" : ""}`} onClick={() => props.onPad(sym)} title={`Say it between two vowels`}>
+ {sym}
+ </button>
+ ) : (
+ <span key={j} className="ipa-empty" />
+ ),
+ )}
+ </td>
+ ))}
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ );
+}
+
+/** Speak mode's right column: what to say, the gestural score, the consonant chart, the tube and folds. */
+export function SpeakRight() {
const body = useStore((s) => s.body);
const f0 = useStore((s) => s.source.f0);
const start = useStore((s) => s.start);
@@ -47,85 +136,80 @@ export function SpeakPanel() {
};
return (
- <div className="speak">
- <div className="panel speak-input">
- <h2>Say something</h2>
- <textarea
- value={text}
- onChange={(e) => setText(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) void speak();
- e.stopPropagation();
- }}
- rows={3}
- spellCheck={!ipa}
- aria-label={ipa ? "IPA to speak" : "Text to speak"}
- placeholder={ipa ? "Type IPA, for example ˈhɛloʊ" : "Type something for the voice to say"}
- />
- <div className="examples">
- {EXAMPLES.map((ex) => (
- <button key={ex} className="chip" onClick={() => { setText(ex); setIpa(false); }}>
- {ex}
- </button>
- ))}
- </div>
- <div className="row">
- <button className="primary" onClick={() => void speak()} disabled={busy}>
- {busy ? "Preparing…" : "Speak"}
- </button>
- <button className="ghost" onClick={stopSpeaking}>Stop</button>
- <Toggle label="Text is IPA" checked={ipa} onChange={setIpa} />
- </div>
- <Slider label="Speaking rate" value={rate} min={0.5} max={1.8} onChange={setRate} format={(v) => `${v.toFixed(2)}×`} />
- <p className="transcription" aria-live="polite">{trans ? `/${trans}/` : "The transcription appears here."}</p>
- </div>
- <div className="panel chart-panel">
- <h2>Consonants, between two vowels</h2>
- <div className="chart-scroll">
- <table className="ipa-chart">
- <thead>
- <tr>
- <th />
- {PLACES.map((p) => (
- <th key={p} scope="col">{p}</th>
- ))}
- </tr>
- </thead>
- <tbody>
- {CHART.map(([manner, cells]) => (
- <tr key={manner}>
- <th scope="row">{manner}</th>
- {cells.map((pair, i) => (
- <td key={i}>
- {pair.map((sym, j) =>
- sym ? (
- <button key={j} className="ipa" onClick={() => void pad(sym)} title={`Say ${vowel}${sym}${vowel}`}>
- {sym}
- </button>
- ) : (
- <span key={j} className="ipa-empty" />
- ),
- )}
- </td>
- ))}
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- <div className="row">
- <span className="dim">Vowel around it</span>
- {["ɑ", "i", "u", "ə"].map((v) => (
- <button key={v} className={`chip${vowel === v ? " on" : ""}`} onClick={() => setVowel(v)}>
- {v}
- </button>
- ))}
+ <div className="right right-speak">
+ <Screen className="s-say" title="Say" sub="Text to speech" tools={<Toggle label="Text is IPA" checked={ipa} onChange={setIpa} />}>
+ <div className="say">
+ <div className="say-row">
+ <textarea
+ value={text}
+ onChange={(e) => setText(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) void speak();
+ e.stopPropagation();
+ }}
+ rows={2}
+ spellCheck={!ipa}
+ aria-label={ipa ? "IPA to speak" : "Text to speak"}
+ placeholder={ipa ? "Type IPA, for example ˈhɛloʊ" : "Type something for the voice to say"}
+ />
+ <div className="say-actions">
+ <button className="primary" onClick={() => void speak()} disabled={busy}>
+ {busy ? "Preparing…" : "Speak"}
+ </button>
+ <button className="ghost" onClick={stopSpeaking}>
+ Stop
+ </button>
+ </div>
+ </div>
+ <div className="say-row">
+ <p className="transcription" aria-live="polite">
+ {trans ? `/${trans}/` : "The transcription appears here."}
+ </p>
+ <div className="say-rate">
+ <Slider label="Rate" value={rate} min={0.5} max={1.8} onChange={setRate} format={(v) => `${v.toFixed(2)}×`} />
+ </div>
+ </div>
+ <div className="examples" role="group" aria-label="Examples">
+ {EXAMPLES.map((ex) => (
+ <Chip
+ key={ex}
+ toggle={false}
+ onClick={() => {
+ setText(ex);
+ setIpa(false);
+ }}
+ >
+ {ex}
+ </Chip>
+ ))}
+ </div>
</div>
- </div>
- <div className="panel score-panel">
- <h2>Gestural score</h2>
+ </Screen>
+ <Screen className="s-score" title="Gestural score">
<ScoreView />
- </div>
+ </Screen>
+ <Screen
+ className="s-chart"
+ title="Consonants"
+ sub="Between two vowels"
+ tools={
+ <div className="vowel-pick" role="group" aria-label="Vowel around it">
+ {["ɑ", "i", "u", "ə"].map((v) => (
+ <Chip key={v} on={vowel === v} onClick={() => setVowel(v)} className="ipa-chip">
+ {v}
+ </Chip>
+ ))}
+ </div>
+ }
+ >
+ <ConsonantChart onPad={(c) => void pad(c)} />
+ </Screen>
+ <Screen className="s-tube" title="Tube" sub="Glottis to lips">
+ <TubeView />
+ </Screen>
+ <Screen className="s-folds" title="Vocal folds" sub="Slowed 100×">
+ <Stroboscope />
+ </Screen>
</div>
);
}
diff --git a/src/ui/render/vector.ts b/src/ui/render/vector.ts
index ed37e36..358ff49 100644
--- a/src/ui/render/vector.ts
+++ b/src/ui/render/vector.ts
@@ -195,6 +195,9 @@ export function ipaGlyph(ctx: CanvasRenderingContext2D, x: number, y: number, ip
case "ʊ": return stroke(`M${f(x - r * 1.15)} ${f(y - xh)}Q${f(x - r * 0.5)} ${f(y - xh * 0.9)} ${f(x - r * 0.75)} ${f(cy)}Q${f(x - r)} ${f(y)} ${f(x)} ${f(y)}Q${f(x + r)} ${f(y)} ${f(x + r * 0.75)} ${f(cy)}Q${f(x + r * 0.5)} ${f(y - xh * 0.9)} ${f(x + r * 1.15)} ${f(y - xh)}`);
case "ʌ": return stroke(`M${f(x - r)} ${f(y)}L${f(x)} ${f(y - xh)}L${f(x + r)} ${f(y)}`);
case "ɤ": return stroke(`M${f(x - r)} ${f(y - xh)}L${f(x)} ${f(y - xh * 0.1)}L${f(x + r)} ${f(y - xh)}M${f(x)} ${f(y - xh * 0.1)}Q${f(x - r * 0.5)} ${f(y + xh * 0.4)} ${f(x)} ${f(y + xh * 0.45)}Q${f(x + r * 0.5)} ${f(y + xh * 0.4)} ${f(x)} ${f(y - xh * 0.1)}`);
+ case "ʃ": return stroke(`M${f(x + r * 0.9)} ${f(y - xh * 1.9)}Q${f(x)} ${f(y - xh * 2.2)} ${f(x)} ${f(y - xh)}L${f(x)} ${f(y + xh * 0.3)}Q${f(x)} ${f(y + xh * 0.95)} ${f(x - r * 0.9)} ${f(y + xh * 0.7)}`);
+ case "θ": return stroke(`M${f(x + r)} ${f(y - xh)}A${f(r)} ${f(xh)} 0 1 0 ${f(x - r)} ${f(y - xh)}A${f(r)} ${f(xh)} 0 1 0 ${f(x + r)} ${f(y - xh)}M${f(x - r)} ${f(y - xh)}L${f(x + r)} ${f(y - xh)}`);
+ case "ŋ": return stroke(`M${f(x - r)} ${f(y)}L${f(x - r)} ${f(y - xh)}M${f(x - r)} ${f(y - xh * 0.6)}Q${f(x - r * 0.2)} ${f(y - xh * 1.1)} ${f(x + r * 0.6)} ${f(y - xh * 0.9)}Q${f(x + r)} ${f(y - xh * 0.75)} ${f(x + r)} ${f(y - xh * 0.4)}L${f(x + r)} ${f(y + xh * 0.4)}Q${f(x + r)} ${f(y + xh * 0.85)} ${f(x + r * 0.3)} ${f(y + xh * 0.8)}`);
case "ə": return stroke(`M${f(x - r)} ${f(cy)}L${f(x + r)} ${f(cy)}A${f(r)} ${f(xh / 2)} 0 1 1 ${f(x - r * 0.75)} ${f(y - xh * 0.85)}`);
case "ɐ": return glyph("a", turned);
case "ɔ": return glyph("c", mirrored);
diff --git a/src/ui/styles.css b/src/ui/styles.css
index 8f51f13..8ad6b3b 100644
--- a/src/ui/styles.css
+++ b/src/ui/styles.css
@@ -1601,19 +1601,19 @@ button.ghost:hover,
gap: 4px;
}
-.view-toggles .toggle {
+.screen-tools .toggle {
position: relative;
display: inline-flex;
}
-.view-toggles .toggle input {
+.screen-tools .toggle input {
position: absolute;
opacity: 0;
width: 1px;
height: 1px;
}
-.view-toggles .toggle span {
+.screen-tools .toggle span {
border: 1px solid var(--frame);
padding: 2px 7px;
font-size: 9px;
@@ -1623,13 +1623,13 @@ button.ghost:hover,
cursor: pointer;
}
-.view-toggles .toggle input:checked + span {
+.screen-tools .toggle input:checked + span {
color: var(--blue);
border-color: var(--blue-dim);
text-shadow: var(--glow-blue);
}
-.view-toggles .toggle input:focus-visible + span {
+.screen-tools .toggle input:focus-visible + span {
outline: 1px dashed var(--blue);
outline-offset: 1px;
}
@@ -1984,3 +1984,234 @@ input[type="range"]::-moz-range-thumb {
min-height: 380px;
}
}
+
+/* ---------- Speak */
+.right-speak {
+ grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
+ grid-template-rows: minmax(0, 192fr) minmax(0, 236fr) minmax(0, 214fr) minmax(0, 190fr);
+ grid-template-areas: "say say" "score score" "chart chart" "tube folds";
+}
+
+.s-say { grid-area: say; }
+.s-score { grid-area: score; }
+.s-chart { grid-area: chart; }
+
+.say {
+ position: absolute;
+ inset: 0;
+ padding: 6px 14px 10px;
+ display: grid;
+ grid-template-rows: auto auto minmax(0, 1fr);
+ gap: 8px;
+ overflow: hidden;
+}
+
+.say-row {
+ display: flex;
+ gap: 10px;
+ align-items: center;
+ min-width: 0;
+}
+
+.say textarea {
+ flex: 1;
+ min-width: 0;
+ height: 44px;
+ resize: none;
+ padding: 6px 10px;
+ font-size: 14px;
+ line-height: 1.35;
+}
+
+.say textarea:focus {
+ outline: none;
+ border-color: var(--blue-dim);
+ box-shadow: 0 0 5px rgba(79, 182, 242, 0.25);
+}
+
+.say-actions {
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+}
+
+.say-actions button {
+ min-width: 84px;
+}
+
+.say .transcription {
+ flex: 1;
+ min-width: 0;
+ margin: 0;
+ color: var(--amber);
+ font-size: 14px;
+ letter-spacing: 0.04em;
+ text-shadow: 0 0 2px rgba(255, 179, 64, 0.6);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.say-rate {
+ width: 170px;
+ flex: none;
+}
+
+.say-rate .slider label {
+ font-size: 9px;
+ margin: 0;
+}
+
+.say-rate input[type="range"] {
+ height: 12px;
+}
+
+.say .examples {
+ display: flex;
+ flex-wrap: nowrap;
+ gap: 4px;
+ align-items: flex-start;
+ overflow-x: auto;
+ scrollbar-width: none;
+}
+
+.say .examples .chip {
+ flex: none;
+}
+
+.say .examples::-webkit-scrollbar {
+ display: none;
+}
+
+.say .examples .chip {
+ font-size: 9px;
+ padding: 2px 7px;
+}
+
+.vowel-pick {
+ display: flex;
+ gap: 4px;
+}
+
+.ipa-chip {
+ text-transform: none;
+ font-size: 12px;
+ padding: 0 8px;
+}
+
+.s-chart .screen-body {
+ overflow: auto;
+}
+
+.s-chart .chart-scroll {
+ position: absolute;
+ inset: 0;
+ padding: 2px 12px 8px;
+ overflow: auto;
+}
+
+.ipa-chart {
+ width: 100%;
+ min-width: 600px;
+ border-collapse: collapse;
+ table-layout: fixed;
+}
+
+.ipa-chart thead th:first-child,
+.ipa-chart tbody th {
+ width: 74px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.ipa-chart th {
+ font-size: 8px;
+ font-weight: 300;
+ letter-spacing: 0.1em;
+ text-transform: uppercase;
+ color: var(--blue-dim);
+ padding: 1px 3px;
+ white-space: nowrap;
+ text-align: center;
+}
+
+.ipa-chart tbody th {
+ text-align: left;
+}
+
+.ipa-chart td {
+ border: 1px solid var(--frame);
+ padding: 0 1px;
+ text-align: center;
+ height: 18px;
+}
+
+.ipa-chart button.ipa {
+ background: transparent;
+ border: 0;
+ border-radius: 0;
+ color: var(--blue);
+ font-family: var(--font);
+ font-size: 12px;
+ line-height: 1.05;
+ padding: 0 4px;
+ text-transform: none;
+ letter-spacing: 0;
+ cursor: pointer;
+}
+
+.ipa-chart button.ipa:hover {
+ background: transparent;
+ color: var(--white);
+ text-shadow: 0 0 3px rgba(238, 246, 248, 0.6);
+}
+
+/* the old rule fixed buttons and gaps at 26 px square, which made the chart taller than its screen */
+.ipa-chart button.ipa,
+.ipa-chart .ipa-empty {
+ width: auto;
+ min-width: 1.3em;
+ height: 16px;
+}
+
+.ipa-chart button.ipa.now {
+ color: var(--green);
+ outline: 1px solid var(--green);
+ outline-offset: 1px;
+ box-shadow: 0 0 6px rgba(91, 227, 129, 0.5);
+ text-shadow: 0 0 3px rgba(91, 227, 129, 0.7);
+}
+
+.screen-body > .score-canvas {
+ display: block;
+ height: 100%;
+}
+
+@media (max-width: 1100px) {
+ .right-speak {
+ grid-template-rows: none;
+ grid-template-areas: "say say" "score score" "chart chart" "tube folds";
+ }
+ .right-speak .screen-body {
+ min-height: 200px;
+ }
+ .s-say .screen-body {
+ min-height: 170px;
+ }
+}
+
+@media (max-width: 640px) {
+ .right-speak {
+ grid-template-columns: minmax(0, 1fr);
+ grid-template-areas: "say" "score" "chart" "tube" "folds";
+ }
+ .s-say .screen-body {
+ min-height: 230px;
+ }
+ .say-row {
+ flex-wrap: wrap;
+ }
+ .say-actions {
+ flex-direction: row;
+ }
+}