From 1890e65b75e280fc907c6b6e885fe1e666dbc3ac Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sat, 10 Dec 2022 22:56:08 +0100 Subject: [PATCH] refactor speak --- packages/core/speak.mjs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/core/speak.mjs b/packages/core/speak.mjs index 25b396b5..6ae95954 100644 --- a/packages/core/speak.mjs +++ b/packages/core/speak.mjs @@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see . */ -import { Pattern, patternify2, reify } from './index.mjs'; +import { register } from './index.mjs'; let synth; try { @@ -16,7 +16,7 @@ try { let allVoices = synth?.getVoices(); // console.log('voices', allVoices); -function speak(words, lang, voice) { +function triggerSpeech(words, lang, voice) { synth.cancel(); const utterance = new SpeechSynthesisUtterance(words); utterance.lang = lang; @@ -31,12 +31,8 @@ function speak(words, lang, voice) { speechSynthesis.speak(utterance); } -Pattern.prototype._speak = function (lang, voice) { - return this.onTrigger((_, hap) => { - speak(hap.value, lang, voice); +export const speak = register('speak', function (lang, voice, pat) { + return pat.onTrigger((_, hap) => { + triggerSpeech(hap.value, lang, voice); }); -}; - -Pattern.prototype.speak = function (lang, voice) { - return patternify2(Pattern.prototype._speak)(reify(lang), reify(voice), this); -}; +});