Skip to content

Commit 59fc8f9

Browse files
committed
Bug 1940906 - Add the unspokenPunctuation attribute to SpeechRecognition. r=media-playback-reviewers,webidl,alwu,smaug
Per spec, unspokenPunctuation defaults to false; the value is stored for round-tripping but does not change recognition behaviour, since Gecko's recognizer is LLM-based and only infers punctuation that was not spoken. Spec: https://webaudio.github.io/web-speech-api/#dom-speechrecognition-unspokenpunctuation WPT: covered by interfaces/speech-api.idl via idlharness. Differential Revision: https://phabricator.services.mozilla.com/D311119
1 parent cb48026 commit 59fc8f9

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎dom/media/webspeech/recognition/SpeechRecognition.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ void SpeechRecognition::SetProcessLocally(bool aProcessLocally) {
388388
mProcessLocally = aProcessLocally;
389389
}
390390

391+
bool SpeechRecognition::UnspokenPunctuation() const {
392+
return mUnspokenPunctuation;
393+
}
394+
395+
void SpeechRecognition::SetUnspokenPunctuation(bool aUnspokenPunctuation) {
396+
mUnspokenPunctuation = aUnspokenPunctuation;
397+
}
398+
391399
void SpeechRecognition::OnSetPhrases(SpeechRecognitionPhrase& aPhrase,
392400
uint32_t aIndex, ErrorResult& aRv) {
393401
// Note: The spec is unclear on whether dynamic updates during recognition

‎dom/media/webspeech/recognition/SpeechRecognition.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class SpeechRecognitionInstallTransaction final {
6363
nsTArray<RefPtr<Promise>> mPromises;
6464
};
6565

66+
// This implements the SpeechRecognition object in the content process, from the
67+
// Web Speech API: https://webaudio.github.io/web-speech-api/#speechrecognition
6668
class SpeechRecognition final : public DOMEventTargetHelper,
6769
public SupportsWeakPtr {
6870
public:
@@ -111,6 +113,9 @@ class SpeechRecognition final : public DOMEventTargetHelper,
111113
bool ProcessLocally() const;
112114
void SetProcessLocally(bool aProcessLocally);
113115

116+
bool UnspokenPunctuation() const;
117+
void SetUnspokenPunctuation(bool aUnspokenPunctuation);
118+
114119
// ObservableArray callbacks for phrases
115120
void OnSetPhrases(SpeechRecognitionPhrase& aPhrase, uint32_t aIndex,
116121
ErrorResult& aRv);
@@ -265,6 +270,10 @@ class SpeechRecognition final : public DOMEventTargetHelper,
265270
bool mInterimResults;
266271
uint32_t mMaxAlternatives;
267272
bool mProcessLocally = false;
273+
// Per spec, defaults to false. The value is stored for round-tripping but
274+
// does not change recognition behaviour: Gecko's recognizer is LLM-based
275+
// and only ever infers punctuation that was not spoken.
276+
bool mUnspokenPunctuation = false;
268277
// The backend gets these at Start() time; spec is unclear on dynamic updates
269278
// Probably better as a SimpleMap or something so it's sparse
270279
// https://github.com/WebAudio/web-speech-api/issues/172

‎dom/webidl/SpeechRecognition.webidl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface SpeechRecognition : EventTarget {
3535
[Throws]
3636
attribute boolean continuous;
3737
attribute boolean interimResults;
38+
attribute boolean unspokenPunctuation;
3839
attribute unsigned long maxAlternatives;
3940

4041
attribute boolean processLocally;

‎testing/web-platform/meta/speech-api/idlharness.https.window.js.ini‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@
424424
if os == "android": FAIL
425425

426426
[SpeechRecognition interface: attribute unspokenPunctuation]
427-
expected: FAIL
428-
427+
expected:
428+
if os == "android": FAIL
429429
[SpeechRecognition interface: new SpeechRecognition() must inherit property "unspokenPunctuation" with the proper type]
430-
expected: FAIL
430+
expected:
431+
if os == "android": FAIL

0 commit comments

Comments
 (0)