From a42e67116949de7207dddbbfd3384dd5c95dcb32 Mon Sep 17 00:00:00 2001 From: Alan Ding Date: Tue, 27 Oct 2026 08:27:31 -0700 Subject: [PATCH] Add speaker diarization attributes and modes to SpeechRecognition --- index.bs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index d446255..909faa9 100644 --- a/index.bs +++ b/index.bs @@ -287,6 +287,9 @@ interface SpeechRecognition : EventTarget { attribute unsigned long maxAlternatives; attribute boolean processLocally; attribute ObservableArray phrases; + attribute SpeechRecognitionDiarization diarization; + attribute unsigned long minSpeakers; + attribute unsigned long maxSpeakers; // methods to drive the speech interaction undefined start(); @@ -316,10 +319,17 @@ enum SpeechRecognitionQuality { "conversation" }; +enum SpeechRecognitionDiarization { + "none", + "speaker-turns", + "speaker-labels" +}; + dictionary SpeechRecognitionOptions { required sequence langs; boolean processLocally = false; SpeechRecognitionQuality quality = "command"; + SpeechRecognitionDiarization diarization = "none"; }; enum SpeechRecognitionErrorCode { @@ -330,7 +340,8 @@ enum SpeechRecognitionErrorCode { "not-allowed", "service-not-allowed", "language-not-supported", - "phrases-not-supported" + "phrases-not-supported", + "diarization-not-supported" }; enum SpeechRecognitionAvailabilityStatus { @@ -367,6 +378,8 @@ interface SpeechRecognitionResult { readonly attribute boolean isFinal; readonly attribute double speechStartTime; readonly attribute double speechEndTime; + readonly attribute boolean speakerChanged; + readonly attribute DOMString? speaker; }; // A collection of responses (used in continuous mode) @@ -472,6 +485,23 @@ interface SpeechRecognitionPhrase {
The getter steps are to return the value of {{SpeechRecognition/[[phrases]]}}.
+ +
diarization attribute
+
This attribute controls speaker diarization for the recognition session. + When set to `"none"`, no speaker segmentation or labeling is performed. + When set to `"speaker-turns"`, the recognition service MUST segment speech recognition results at speaker turn boundaries, ensuring that each {{SpeechRecognitionResult}} represents speech from a single speaker. + When set to `"speaker-labels"`, the recognition service MUST segment results at speaker turn boundaries and assign a canonical speaker label (`"1"`, `"2"`, etc.) to each result's {{SpeechRecognitionResult/speaker}} attribute. + The default value is `"none"`.
+ +
minSpeakers attribute
+
This attribute provides an advisory lower bound on the expected number of distinct speakers in the session. + The default value is `0` (indicating no hint provided). + If both {{SpeechRecognition/minSpeakers}} and {{SpeechRecognition/maxSpeakers}} are non-zero and `minSpeakers > maxSpeakers`, calling {{SpeechRecognition/start()}} MUST throw a {{RangeError}} exception.
+ +
maxSpeakers attribute
+
This attribute sets an upper bound on the maximum number of distinct speakers to distinguish in the session. + The default value is `0` (indicating no limit or hint provided). + When set to a positive value and {{SpeechRecognition/diarization}} is `"speaker-labels"`, the speech recognition service MUST NOT assign speaker labels outside the range of 1 to `maxSpeakers`.

The group has discussed whether WebRTC might be used to specify selection of audio sources and remote recognizers. @@ -664,6 +694,10 @@ following steps: 1. If this.{{SpeechRecognition/phrases}}'s `length` is greater than 0 and the user agent does not support contextual biasing: 1. [=Queue a task=] to [=fire an event=] named error at [=this=] using {{SpeechRecognitionErrorEvent}} with its {{SpeechRecognitionErrorEvent/error}} attribute initialized to `phrases-not-supported` and its {{SpeechRecognitionErrorEvent/message}} attribute set to an implementation-defined string detailing the reason. 1. Abort these steps. +1. If this.{{SpeechRecognition/minSpeakers}} is greater than 0 and this.{{SpeechRecognition/maxSpeakers}} is greater than 0 and this.{{SpeechRecognition/minSpeakers}} is greater than this.{{SpeechRecognition/maxSpeakers}}, throw a {{RangeError}} and abort these steps. +1. If this.{{SpeechRecognition/diarization}} is NOT `"none"` and the speech recognition service does not support the requested diarization mode: + 1. [=Queue a task=] to [=fire an event=] named error at [=this=] using {{SpeechRecognitionErrorEvent}} with its {{SpeechRecognitionErrorEvent/error}} attribute initialized to `diarization-not-supported` and its {{SpeechRecognitionErrorEvent/message}} attribute set to an implementation-defined string detailing the reason. + 1. Abort these steps. 1. Regardless of the value of this.{{SpeechRecognition/[[processLocally]]}}, the user agent MUST treat an on-device language pack whose [=download masking state=] is not "unmasked" for the caller's [=storage key=] as not available for local speech recognition. If this.{{SpeechRecognition/[[processLocally]]}} is `true`, or if the user agent otherwise attempts to perform local speech recognition (for example, when remote speech recognition is not supported or not used): 1. If the user agent determines that local speech recognition is not available for this.{{SpeechRecognition/lang}} (including when its [=download masking state=] is not "unmasked" for the caller's [=storage key=] or when a previously installed language pack was evicted and is no longer usable; see the download masking requirements and the eviction failure requirements below), or if it cannot fulfill local processing for other reasons (such as preventing resource exhaustion): 1. [=Queue a task=] to [=fire an event=] named error at [=this=] using {{SpeechRecognitionErrorEvent}} with its {{SpeechRecognitionErrorEvent/error}} attribute initialized to {{SpeechRecognitionErrorCode/service-not-allowed}} and its {{SpeechRecognitionErrorEvent/message}} attribute set to an implementation-defined string detailing the reason, which MUST NOT reveal whether a language pack whose [=download masking state=] is not "unmasked" for the caller's [=storage key=] is installed or being downloaded. @@ -825,6 +859,16 @@ For example, some implementations may fire audioe

speechEndTime attribute
A {{double}} representing the end of the speech segment corresponding to this recognition result, as an offset in seconds on the [=session audio timeline=].
+ +
speakerChanged attribute
+
A boolean indicating whether the speaker for this result is different from the speaker of the preceding final result in the recognition session. + For the first result in a session, {{SpeechRecognitionResult/speakerChanged}} MUST be `false`. + When {{SpeechRecognition/diarization}} is `"none"`, {{SpeechRecognitionResult/speakerChanged}} MUST be `false`.
+ +
speaker attribute
+
A {{DOMString}} identifying the speaker associated with this result, or `null` if speaker identification is disabled or undetermined. + When {{SpeechRecognition/diarization}} is `"speaker-labels"`, this attribute MUST be set to a canonical 1-based index string (`"1"`, `"2"`, `"3"`, ...) assigned in order of speaker appearance within the recognition session. + When {{SpeechRecognition/diarization}} is `"none"` or `"speaker-turns"`, this attribute MUST be `null`.

@@ -833,6 +877,11 @@ For example, some implementations may fire audioe Their precision is implementation-defined.

+

+ Speaker labels are scoped strictly to the recognition session and reset when a new session starts. + Once a {{SpeechRecognitionResult}} is finalized ({{SpeechRecognitionResult/isFinal}} is `true`), its {{SpeechRecognitionResult/speaker}} and {{SpeechRecognitionResult/speakerChanged}} attributes are immutable. +

+

SpeechRecognitionResultList

The SpeechRecognitionResultList object holds a sequence of recognition results representing the complete return result of a continuous recognition.