Truly independent web browser
LibWeb: Implement speech synthesis in Rust
Shannon Booth3d1192ecf59e
diff --git a/Libraries/LibWeb/Bindings/Rust/src/speech/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/speech/mod.rsindex cb60cc23e36..cc1112f1f78 100644--- a/Libraries/LibWeb/Bindings/Rust/src/speech/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/speech/mod.rs@@ -22,3 +22,9 @@ pub(crate) mod speech_recognition_phrase;pub(crate) mod speech_recognition_result;#[cfg(not(test))]pub(crate) mod speech_recognition_result_list;+#[cfg(not(test))]+pub(crate) mod speech_synthesis;+#[cfg(not(test))]+pub(crate) mod speech_synthesis_utterance;+#[cfg(not(test))]+pub(crate) mod speech_synthesis_voice;diff --git a/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis.rs b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis.rsnew file mode 100644index 00000000000..cb607fdd8fa--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis.rs@@ -0,0 +1,100 @@+/*+ * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! SpeechSynthesis, https://wicg.github.io/speech-api/#speechsynthesis++use core::ffi::c_void;+use core::ptr::NonNull;++use libjs_rust::api::{MarkedVec, Trace, Vm};++use super::speech_synthesis_voice::SpeechSynthesisVoice;+use crate::bindings::event_target::{CppEventTarget, GetTheParent};+use crate::bindings::interface::{Ref, Wrappable, allocate, cell_into_abi};+use crate::bindings::{CallContext, WebIdlResult};++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct SpeechSynthesis {+ event_target: CppEventTarget,+ pending: bool,+ speaking: bool,+ paused: bool,+ voices: Vec<Ref<SpeechSynthesisVoice>>,+}++impl Wrappable for SpeechSynthesis {+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {+ self.event_target.as_cpp_parent()+ }+}++impl GetTheParent for SpeechSynthesis {+ fn get_the_parent(&self) -> Option<CppEventTarget> {+ None+ }+}++#[expect(+ clippy::unnecessary_wraps,+ reason = "the bindings call every method of an implementation for its WebIDL result, whether or not it can fail"+)]+impl SpeechSynthesis {+ fn create(vm: &Vm) -> Ref<Self> {+ let synthesis = allocate(vm, |_| Self {+ event_target: CppEventTarget::new(),+ pending: false,+ speaking: false,+ paused: false,+ voices: Vec::new(),+ });+ synthesis.event_target.set_owner(synthesis);+ synthesis+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesis-pending+ pub(crate) fn pending(&self, _: &mut CallContext) -> WebIdlResult<bool> {+ Ok(self.pending)+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesis-speaking+ pub(crate) fn speaking(&self, _: &mut CallContext) -> WebIdlResult<bool> {+ Ok(self.speaking)+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesis-paused+ pub(crate) fn paused(&self, _: &mut CallContext) -> WebIdlResult<bool> {+ Ok(self.paused)+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesis-cancel+ pub(crate) fn cancel(&self, _: &mut CallContext) -> WebIdlResult<()> {+ eprintln!("FIXME: Implement SpeechSynthesis::cancel()");+ Ok(())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesis-getvoices+ pub(crate) fn get_voices<'vm>(+ &self,+ cx: &mut CallContext<'vm>,+ ) -> WebIdlResult<MarkedVec<'vm, Ref<SpeechSynthesisVoice>>> {+ // FIXME: Populate voices with available synthesis voices.+ let voices = MarkedVec::new(cx.vm());+ voices.extend_from_slice(&self.voices);+ Ok(voices)+ }+}++/// # Safety+///+/// The VM must be live.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_rust_speech_synthesis_create(vm: *const c_void) -> *mut c_void {+ // SAFETY: The caller passes a live VM.+ let vm = unsafe { &*vm.cast::<Vm>() };+ cell_into_abi(SpeechSynthesis::create(vm))+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis_utterance.rs b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis_utterance.rsnew file mode 100644index 00000000000..0a08f7f68e9--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis_utterance.rs@@ -0,0 +1,126 @@+/*+ * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! SpeechSynthesisUtterance, https://wicg.github.io/speech-api/#speechsynthesisutterance++use core::cell::{Cell, RefCell};+use core::ffi::c_void;+use core::ptr::NonNull;++use ak::Utf16String;+use libjs_rust::api::Trace;++use super::speech_synthesis_voice::SpeechSynthesisVoice;+use crate::bindings::event_target::{CppEventTarget, GetTheParent};+use crate::bindings::interface::{Ref, Wrappable, allocate};+use crate::bindings::{CallContext, WebIdlResult};++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct SpeechSynthesisUtterance {+ event_target: CppEventTarget,+ #[gc(untraced)]+ text: RefCell<Utf16String>,+ #[gc(untraced)]+ lang: RefCell<Utf16String>,+ voice: Cell<Option<Ref<SpeechSynthesisVoice>>>,+ volume: Cell<f32>,+ rate: Cell<f32>,+ pitch: Cell<f32>,+}++impl Wrappable for SpeechSynthesisUtterance {+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {+ self.event_target.as_cpp_parent()+ }+}++impl GetTheParent for SpeechSynthesisUtterance {+ fn get_the_parent(&self) -> Option<CppEventTarget> {+ None+ }+}++#[expect(+ clippy::unnecessary_wraps,+ reason = "the bindings call every method of an implementation for its WebIDL result, whether or not it can fail"+)]+impl SpeechSynthesisUtterance {+ pub(crate) fn construct(cx: &mut CallContext, text: Utf16String) -> WebIdlResult<Ref<Self>> {+ let utterance = allocate(cx.vm(), |_| Self {+ event_target: CppEventTarget::new(),+ text: RefCell::new(text),+ lang: RefCell::new(Utf16String::default()),+ voice: Cell::new(None),+ volume: Cell::new(1.0),+ rate: Cell::new(1.0),+ pitch: Cell::new(1.0),+ });+ utterance.event_target.set_owner(utterance);+ Ok(utterance)+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-text+ pub(crate) fn text(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.text.borrow().clone())+ }++ pub(crate) fn set_text(&self, _: &mut CallContext, text: Utf16String) -> WebIdlResult<()> {+ *self.text.borrow_mut() = text;+ Ok(())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-lang+ pub(crate) fn lang(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.lang.borrow().clone())+ }++ pub(crate) fn set_lang(&self, _: &mut CallContext, lang: Utf16String) -> WebIdlResult<()> {+ *self.lang.borrow_mut() = lang;+ Ok(())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-voice+ pub(crate) fn voice(&self, _: &mut CallContext) -> WebIdlResult<Option<Ref<SpeechSynthesisVoice>>> {+ Ok(self.voice.get())+ }++ pub(crate) fn set_voice(&self, _: &mut CallContext, voice: Option<Ref<SpeechSynthesisVoice>>) -> WebIdlResult<()> {+ self.voice.set(voice);+ Ok(())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-volume+ pub(crate) fn volume(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ Ok(self.volume.get())+ }++ pub(crate) fn set_volume(&self, _: &mut CallContext, volume: f32) -> WebIdlResult<()> {+ self.volume.set(volume);+ Ok(())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-rate+ pub(crate) fn rate(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ Ok(self.rate.get())+ }++ pub(crate) fn set_rate(&self, _: &mut CallContext, rate: f32) -> WebIdlResult<()> {+ self.rate.set(rate);+ Ok(())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-pitch+ pub(crate) fn pitch(&self, _: &mut CallContext) -> WebIdlResult<f32> {+ Ok(self.pitch.get())+ }++ pub(crate) fn set_pitch(&self, _: &mut CallContext, pitch: f32) -> WebIdlResult<()> {+ self.pitch.set(pitch);+ Ok(())+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis_voice.rs b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis_voice.rsnew file mode 100644index 00000000000..90a5405e761--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/speech/speech_synthesis_voice.rs@@ -0,0 +1,57 @@+/*+ * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! SpeechSynthesisVoice, https://wicg.github.io/speech-api/#speechsynthesisvoice++use ak::Utf16String;+use libjs_rust::api::Trace;++use crate::bindings::interface::Wrappable;+use crate::bindings::{CallContext, WebIdlResult};++#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct SpeechSynthesisVoice {+ voice_uri: Utf16String,+ name: Utf16String,+ lang: Utf16String,+ local_service: bool,+ default: bool,+}++impl Wrappable for SpeechSynthesisVoice {}++#[expect(+ clippy::unnecessary_wraps,+ reason = "the bindings call every method of an implementation for its WebIDL result, whether or not it can fail"+)]+impl SpeechSynthesisVoice {+ // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-voiceuri+ pub(crate) fn voice_uri(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.voice_uri.clone())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-name+ pub(crate) fn name(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.name.clone())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-lang+ pub(crate) fn lang(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.lang.clone())+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-localservice+ pub(crate) fn local_service(&self, _: &mut CallContext) -> WebIdlResult<bool> {+ Ok(self.local_service)+ }++ // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-default+ pub(crate) fn is_default(&self, _: &mut CallContext) -> WebIdlResult<bool> {+ Ok(self.default)+ }+}diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex 110593aa76f..2b5e93b6fd0 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -761,8 +761,6 @@ set(SOURCESServiceWorker/ServiceWorkerRecord.cppServiceWorker/ServiceWorkerRegistration.cppSpeech/SpeechSynthesis.cpp- Speech/SpeechSynthesisUtterance.cpp- Speech/SpeechSynthesisVoice.cppSRI/IntegrityPolicy.cppSRI/SRI.cppStorageAPI/NavigatorStorage.cppdiff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex edb5c8853de..3c67ebcd772 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -1082,8 +1082,6 @@ using WorkerType = Bindings::WorkerType;namespace Web::Speech {class SpeechSynthesis;-class SpeechSynthesisUtterance;-class SpeechSynthesisVoice;}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesis.cpp b/Libraries/LibWeb/Speech/SpeechSynthesis.cppindex 1386acb520a..1b10c5dab2d 100644--- a/Libraries/LibWeb/Speech/SpeechSynthesis.cpp+++ b/Libraries/LibWeb/Speech/SpeechSynthesis.cpp@@ -4,54 +4,19 @@* SPDX-License-Identifier: BSD-2-Clause*/-#include <LibGC/Heap.h>-#include <LibWeb/HTML/EventNames.h>+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/Speech/SpeechSynthesis.h>-#include <LibWeb/Speech/SpeechSynthesisVoice.h>namespace Web::Speech {-GC_DEFINE_ALLOCATOR(SpeechSynthesis);--GC::Ref<SpeechSynthesis> SpeechSynthesis::create()-{- return GC::Heap::the().allocate<SpeechSynthesis>();-}--SpeechSynthesis::SpeechSynthesis()- : DOM::EventTarget()-{-}--SpeechSynthesis::~SpeechSynthesis() = default;--void SpeechSynthesis::visit_edges(Cell::Visitor& visitor)-{- Base::visit_edges(visitor);- visitor.visit(m_voices);+extern "C" {+SpeechSynthesis* web_rust_speech_synthesis_create(JSVM*);}-void SpeechSynthesis::set_onvoiceschanged(GC::Ptr<WebIDL::CallbackType> event_handler)-{- set_event_handler_attribute(HTML::EventNames::voiceschanged, event_handler);-}--GC::Ptr<WebIDL::CallbackType> SpeechSynthesis::onvoiceschanged()-{- return event_handler_attribute(HTML::EventNames::voiceschanged);-}--// https://wicg.github.io/speech-api/#dom-speechsynthesis-cancel-void SpeechSynthesis::cancel()-{- dbgln("FIXME: Implement SpeechSynthesis::cancel()");-}--// https://wicg.github.io/speech-api/#dom-speechsynthesis-getvoices-ReadonlySpan<GC::Ref<SpeechSynthesisVoice>> SpeechSynthesis::get_voices() const+GC::Ref<SpeechSynthesis> SpeechSynthesis::create(){- // FIXME: Populate m_voices with available synthesis voices.- return m_voices;+ return *web_rust_speech_synthesis_create(JS::HostABI::vm_to_abi(JS::VM::the()));}}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesis.h b/Libraries/LibWeb/Speech/SpeechSynthesis.hindex bb47ef98f9e..d1223c67059 100644--- a/Libraries/LibWeb/Speech/SpeechSynthesis.h+++ b/Libraries/LibWeb/Speech/SpeechSynthesis.h@@ -6,47 +6,16 @@#pragma once-#include <AK/Vector.h>-#include <LibGC/Ptr.h>-#include <LibJS/Forward.h>-#include <LibWeb/DOM/EventTarget.h>-#include <LibWeb/Forward.h>+#include <LibWeb/Bindings/RustInterface.h>+#include <LibWeb/Bindings/SpeechSynthesis.h>namespace Web::Speech {-class SpeechSynthesis final : public DOM::EventTarget {- WEB_WRAPPABLE(SpeechSynthesis, DOM::EventTarget);- GC_DECLARE_ALLOCATOR(SpeechSynthesis);+class SpeechSynthesis : public Bindings::RustInterfaceCell {+ WEB_RUST_INTERFACE(SpeechSynthesis, speech_synthesis)public:[[nodiscard]] static GC::Ref<SpeechSynthesis> create();- virtual ~SpeechSynthesis() override;-- // https://wicg.github.io/speech-api/#dom-speechsynthesis-pending- bool pending() const { return m_pending; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesis-speaking- bool speaking() const { return m_speaking; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesis-paused- bool paused() const { return m_paused; }-- void set_onvoiceschanged(GC::Ptr<WebIDL::CallbackType>);- GC::Ptr<WebIDL::CallbackType> onvoiceschanged();-- void cancel();-- ReadonlySpan<GC::Ref<SpeechSynthesisVoice>> get_voices() const;--private:- explicit SpeechSynthesis();-- virtual void visit_edges(Cell::Visitor&) override;-- bool m_pending { false };- bool m_speaking { false };- bool m_paused { false };- Vector<GC::Ref<SpeechSynthesisVoice>> m_voices;};}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesis.idl b/Libraries/LibWeb/Speech/SpeechSynthesis.idlindex 0f2b8bbb7e5..8865677a771 100644--- a/Libraries/LibWeb/Speech/SpeechSynthesis.idl+++ b/Libraries/LibWeb/Speech/SpeechSynthesis.idl@@ -1,5 +1,5 @@// https://wicg.github.io/speech-api/#speechsynthesis-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface SpeechSynthesis : EventTarget {readonly attribute boolean pending;readonly attribute boolean speaking;diff --git a/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.cpp b/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.cppdeleted file mode 100644index dc082241ca6..00000000000--- a/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.cpp+++ /dev/null@@ -1,47 +0,0 @@-/*- * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibGC/Heap.h>-#include <LibWeb/Speech/SpeechSynthesisUtterance.h>-#include <LibWeb/Speech/SpeechSynthesisVoice.h>--namespace Web::Speech {--GC_DEFINE_ALLOCATOR(SpeechSynthesisUtterance);--GC::Ref<SpeechSynthesisUtterance> SpeechSynthesisUtterance::create(Utf16String const& text)-{- return GC::Heap::the().allocate<SpeechSynthesisUtterance>(text);-}--SpeechSynthesisUtterance::SpeechSynthesisUtterance(Utf16String const& text)- : DOM::EventTarget()- , m_text(text)-{-}--SpeechSynthesisUtterance::~SpeechSynthesisUtterance() = default;--void SpeechSynthesisUtterance::visit_edges(Cell::Visitor& visitor)-{- Base::visit_edges(visitor);- visitor.visit(m_voice);-}--#undef __ENUMERATE-#define __ENUMERATE(attribute_name, event_name) \- void SpeechSynthesisUtterance::set_##attribute_name(GC::Ptr<WebIDL::CallbackType> value) \- { \- set_event_handler_attribute(event_name, value); \- } \- GC::Ptr<WebIDL::CallbackType> SpeechSynthesisUtterance::attribute_name() \- { \- return event_handler_attribute(event_name); \- }-ENUMERATE_SPEECH_SYNTHESIS_UTTERANCE_EVENT_HANDLERS(__ENUMERATE)-#undef __ENUMERATE--}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.h b/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.hdeleted file mode 100644index 77fcd1cf92d..00000000000--- a/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.h+++ /dev/null@@ -1,81 +0,0 @@-/*- * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16String.h>-#include <LibGC/Ptr.h>-#include <LibJS/Forward.h>-#include <LibWeb/DOM/EventTarget.h>-#include <LibWeb/Forward.h>-#include <LibWeb/HTML/EventNames.h>-#include <LibWeb/WebIDL/ExceptionOr.h>--#define ENUMERATE_SPEECH_SYNTHESIS_UTTERANCE_EVENT_HANDLERS(E) \- E(onstart, HTML::EventNames::start) \- E(onend, HTML::EventNames::end) \- E(onerror, HTML::EventNames::error) \- E(onpause, HTML::EventNames::pause) \- E(onresume, HTML::EventNames::resume) \- E(onmark, HTML::EventNames::mark) \- E(onboundary, HTML::EventNames::boundary)--namespace Web::Speech {--class SpeechSynthesisUtterance final : public DOM::EventTarget {- WEB_WRAPPABLE(SpeechSynthesisUtterance, DOM::EventTarget);- GC_DECLARE_ALLOCATOR(SpeechSynthesisUtterance);--public:- static constexpr size_t voice_offset() { return offsetof(SpeechSynthesisUtterance, m_voice); }- static GC::Ref<SpeechSynthesisUtterance> create(Utf16String const& text = {});- virtual ~SpeechSynthesisUtterance() override;-- // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-text- Utf16String const& text() const { return m_text; }- void set_text(Utf16String const& text) { m_text = text; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-lang- Utf16String const& lang() const { return m_lang; }- void set_lang(Utf16String const& lang) { m_lang = lang; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-voice- GC::Ptr<SpeechSynthesisVoice> voice() const { return m_voice; }- void set_voice(GC::Ptr<SpeechSynthesisVoice> voice) { m_voice = voice; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-volume- float volume() const { return m_volume; }- void set_volume(float volume) { m_volume = volume; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-rate- float rate() const { return m_rate; }- void set_rate(float rate) { m_rate = rate; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisutterance-pitch- float pitch() const { return m_pitch; }- void set_pitch(float pitch) { m_pitch = pitch; }--#undef __ENUMERATE-#define __ENUMERATE(attribute_name, event_name) \- void set_##attribute_name(GC::Ptr<WebIDL::CallbackType>); \- GC::Ptr<WebIDL::CallbackType> attribute_name();- ENUMERATE_SPEECH_SYNTHESIS_UTTERANCE_EVENT_HANDLERS(__ENUMERATE)-#undef __ENUMERATE--private:- explicit SpeechSynthesisUtterance(Utf16String const& text);-- virtual void visit_edges(Cell::Visitor&) override;-- Utf16String m_text;- Utf16String m_lang;- GC::Ptr<SpeechSynthesisVoice> m_voice;- float m_volume { 1.f };- float m_rate { 1.f };- float m_pitch { 1.f };-};--}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.idl b/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.idlindex 3095eaa52cb..303250c769d 100644--- a/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.idl+++ b/Libraries/LibWeb/Speech/SpeechSynthesisUtterance.idl@@ -1,11 +1,11 @@// https://wicg.github.io/speech-api/#speechsynthesisutterance-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface SpeechSynthesisUtterance : EventTarget {constructor(optional DOMString text = "");attribute DOMString text;attribute DOMString lang;- [DirectGetter] attribute SpeechSynthesisVoice? voice;+ attribute SpeechSynthesisVoice? voice;attribute float volume;attribute float rate;attribute float pitch;diff --git a/Libraries/LibWeb/Speech/SpeechSynthesisVoice.cpp b/Libraries/LibWeb/Speech/SpeechSynthesisVoice.cppdeleted file mode 100644index 7270f68af14..00000000000--- a/Libraries/LibWeb/Speech/SpeechSynthesisVoice.cpp+++ /dev/null@@ -1,25 +0,0 @@-/*- * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibGC/Heap.h>-#include <LibWeb/Speech/SpeechSynthesisVoice.h>--namespace Web::Speech {--GC_DEFINE_ALLOCATOR(SpeechSynthesisVoice);--GC::Ref<SpeechSynthesisVoice> SpeechSynthesisVoice::create()-{- return GC::Heap::the().allocate<SpeechSynthesisVoice>();-}--SpeechSynthesisVoice::SpeechSynthesisVoice()-{-}--SpeechSynthesisVoice::~SpeechSynthesisVoice() = default;--}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesisVoice.h b/Libraries/LibWeb/Speech/SpeechSynthesisVoice.hdeleted file mode 100644index a7e2a3e6953..00000000000--- a/Libraries/LibWeb/Speech/SpeechSynthesisVoice.h+++ /dev/null@@ -1,50 +0,0 @@-/*- * Copyright (c) 2026, Jelle Raaijmakers <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16String.h>-#include <LibGC/Ptr.h>-#include <LibJS/Forward.h>-#include <LibWeb/Bindings/Wrappable.h>-#include <LibWeb/Forward.h>--namespace Web::Speech {--class SpeechSynthesisVoice final : public Bindings::GCAllocatedWrappable {- WEB_WRAPPABLE(SpeechSynthesisVoice, Bindings::GCAllocatedWrappable);- GC_DECLARE_ALLOCATOR(SpeechSynthesisVoice);--public:- [[nodiscard]] static GC::Ref<SpeechSynthesisVoice> create();- virtual ~SpeechSynthesisVoice() override;-- // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-voiceuri- Utf16String const& voice_uri() const { return m_voice_uri; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-name- Utf16String const& name() const { return m_name; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-lang- Utf16String const& lang() const { return m_lang; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-localservice- bool local_service() const { return m_local_service; }-- // https://wicg.github.io/speech-api/#dom-speechsynthesisvoice-default- bool is_default() const { return m_default; }--private:- explicit SpeechSynthesisVoice();-- Utf16String m_voice_uri;- Utf16String m_name;- Utf16String m_lang;- bool m_local_service { false };- bool m_default { false };-};--}diff --git a/Libraries/LibWeb/Speech/SpeechSynthesisVoice.idl b/Libraries/LibWeb/Speech/SpeechSynthesisVoice.idlindex a1d7b4c100d..b51105ca4f4 100644--- a/Libraries/LibWeb/Speech/SpeechSynthesisVoice.idl+++ b/Libraries/LibWeb/Speech/SpeechSynthesisVoice.idl@@ -1,5 +1,5 @@// https://wicg.github.io/speech-api/#speechsynthesisvoice-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface SpeechSynthesisVoice {readonly attribute DOMString voiceURI;readonly attribute DOMString name;diff --git a/Tests/LibWeb/Text/expected/wpt-import/speech-api/SpeechSynthesisUtterance-basics.https.txt b/Tests/LibWeb/Text/expected/wpt-import/speech-api/SpeechSynthesisUtterance-basics.https.txtnew file mode 100644index 00000000000..b861d155353--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/speech-api/SpeechSynthesisUtterance-basics.https.txt@@ -0,0 +1,15 @@+Harness status: OK++Found 10 tests++10 Pass+Pass new SpeechSynthesisUtterance() default text+Pass new SpeechSynthesisUtterance() default lang+Pass new SpeechSynthesisUtterance() default voice+Pass new SpeechSynthesisUtterance() default volume+Pass new SpeechSynthesisUtterance() default rate+Pass new SpeechSynthesisUtterance() default pitch+Pass new SpeechSynthesisUtterance("hello") text and defaults+Pass new SpeechSynthesisUtterance(null)+Pass new SpeechSynthesisUtterance(undefined)+Pass SpeechSynthesisUtterance text setter\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/speech-api/SpeechSynthesisUtterance-basics.https.html b/Tests/LibWeb/Text/input/wpt-import/speech-api/SpeechSynthesisUtterance-basics.https.htmlnew file mode 100644index 00000000000..36418a5e46c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/speech-api/SpeechSynthesisUtterance-basics.https.html@@ -0,0 +1,51 @@+<!DOCTYPE html>+<title>SpeechSynthesisUtterance basics</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<script>+const DEFAULTS = {+ text: '',+ lang: '',+ voice: null,+ volume: 1,+ rate: 1,+ pitch: 1,+};++for (const prop in DEFAULTS) {+ test(function() {+ const utt = new SpeechSynthesisUtterance();+ assert_equals(utt[prop], DEFAULTS[prop], prop);+ }, `new SpeechSynthesisUtterance() default ${prop}`);+}++test(function() {+ const utt = new SpeechSynthesisUtterance("hello");+ assert_equals(utt.text, 'hello', 'text');+ // check that the other properties retain their defaults+ for (const prop in DEFAULTS) {+ if (prop != 'text') {+ assert_equals(utt[prop], DEFAULTS[prop], prop);+ }+ }+}, 'new SpeechSynthesisUtterance("hello") text and defaults');++test(function() {+ const utt = new SpeechSynthesisUtterance(null);+ assert_equals(utt.text, 'null');+}, 'new SpeechSynthesisUtterance(null)');++test(function() {+ const utt = new SpeechSynthesisUtterance(undefined);+ // See https://github.com/w3c/speech-api/pull/48.+ assert_equals(utt.text, '');+}, 'new SpeechSynthesisUtterance(undefined)');++test(function() {+ const utt = new SpeechSynthesisUtterance();+ utt.text = 'word';+ assert_equals(utt.text, 'word');+}, 'SpeechSynthesisUtterance text setter');++// TODO: setters https://github.com/w3c/speech-api/issues/29+</script>