Skip to content

Commit 037bc75

Browse files
committed
Add explainer for unspokenPunctuation
1 parent 1a0e44a commit 037bc75

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

explainers/unspoken-punctuation.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Explainer: Unspoken Punctuation for the Web Speech API
2+
3+
## Introduction
4+
5+
The Web Speech API provides powerful speech recognition capabilities to web applications. However, continuous speech often lacks explicit spoken punctuation commands. When building casual voice typing tools, automated transcription services, and conversational assistants, developers frequently need to post-process the raw text to insert punctuation, making it readable and natural.
6+
7+
To address this, we introduce **unspoken punctuation** to the Web Speech API. This feature allows developers to configure the speech recognition engine to automatically infer and insert punctuation marks (such as periods, commas, and question marks) based on natural pauses, grammatical structure, and prosody, without requiring the user to explicitly speak the punctuation commands (e.g. saying "period" or "comma").
8+
9+
## Why Use Unspoken Punctuation?
10+
11+
### 1. **Customization for Different Use Cases**
12+
Different speech recognition contexts require distinct handling of text flow. Casual voice typing, automated transcription, and conversational assistants greatly benefit from automatic punctuation to produce readable, polished text out of the box. Conversely, precise dictation tools, coding via voice, or raw acoustic logging applications may require verbatim, unpunctuated streams where punctuation is strictly controlled by explicit user commands.
13+
14+
### 2. **Enhanced User Experience**
15+
Natural, continuous speech often lacks explicit spoken punctuation commands. Allowing developers to enable automatic punctuation lowers the cognitive load for end-users, making voice input feel more intuitive and conversational while saving developers from implementing complex downstream NLP models to handle basic text formatting.
16+
17+
## New API Components
18+
19+
The unspoken punctuation feature is implemented through a new `unspokenPunctuation` boolean attribute on the `SpeechRecognition` interface.
20+
21+
### `SpeechRecognition.unspokenPunctuation` attribute
22+
This boolean attribute controls whether the speech recognition engine automatically infers and inserts punctuation marks.
23+
24+
- When set to `true`, the user agent should automatically insert punctuation based on natural pauses and grammatical structure.
25+
- When set to `false`, the user agent must not insert unspoken punctuation, requiring the user to explicitly dictate punctuation commands.
26+
- The default value is `false` to maintain backward compatibility with existing applications and ensure deterministic, unformatted text outputs unless explicitly opted into by the developer.
27+
28+
## Example Usage
29+
30+
```javascript
31+
const recognition = new SpeechRecognition();
32+
33+
// Enable unspoken punctuation
34+
recognition.unspokenPunctuation = true;
35+
36+
// Configure other settings
37+
recognition.continuous = true;
38+
recognition.interimResults = true;
39+
recognition.lang = 'en-US';
40+
41+
recognition.onresult = (event) => {
42+
for (let i = event.resultIndex; i < event.results.length; ++i) {
43+
if (event.results[i].isFinal) {
44+
console.log('Final Result with Punctuation: ', event.results[i][0].transcript);
45+
// Example output: "Hello there, how are you today?"
46+
// Instead of: "hello there how are you today"
47+
} else {
48+
console.log('Interim Result: ', event.results[i][0].transcript);
49+
}
50+
}
51+
};
52+
53+
recognition.start();
54+
```

0 commit comments

Comments
 (0)