All files / lib/os/neurals/audio tts.ts

0% Statements 0/14
0% Branches 0/1
0% Functions 0/1
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15                             
export function speak(text: string, opts: Partial<SpeechSynthesisUtterance> = {}) {
  if (typeof window === 'undefined' || !('speechSynthesis' in window)) return;
  const u = new SpeechSynthesisUtterance(text);
  u.lang = opts.lang || 'en-US';
  u.rate = opts.rate ?? 1.02;
  u.pitch = opts.pitch ?? 1;
  if (opts.voice) u.voice = opts.voice;
  window.speechSynthesis.cancel();
  window.speechSynthesis.speak(u);
}
export function stopSpeak() {
  if (typeof window === 'undefined') return;
  window.speechSynthesis?.cancel();
}