Skip to content

Commit d4a19b5

Browse files
committed
feat: allowing the speak method to accept options and deprecating the speakWithOptions method
1 parent e409128 commit d4a19b5

2 files changed

Lines changed: 31 additions & 23 deletions

File tree

docs/USAGE.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,13 @@ Speech.reset();
268268

269269
### Speaking Text
270270

271-
Speak a given text using the current global settings.
271+
Speak a given text using the current global settings, or provide per-utterance options.
272272

273273
**API Definition:**
274274

275275
```ts
276276
Speech.speak(text: string): Promise<string>
277+
Speech.speak(text: string, options: VoiceOptions): Promise<string>
277278
```
278279

279280
**Returns:**
@@ -293,41 +294,39 @@ Speech.onFinish(({id: eventId}) => {
293294
});
294295
```
295296

296-
---
297-
298-
### Speaking Text with Custom Options
299-
300-
Override global options for a specific utterance.
301-
302-
**API Definition:**
303-
304297
```ts
305-
Speech.speakWithOptions(text: string, options: VoiceOptions): Promise<string>
306-
```
307-
308-
**Returns:**
309-
310-
- A unique utterance ID (string) returned immediately when the utterance is queued. Use it to filter events for this specific speech operation.
311-
312-
**Example Usage:**
313-
314-
```ts
315-
const id = await Speech.speakWithOptions('Hello!', {
298+
const id2 = await Speech.speak('Hello!', {
316299
language: 'en-US',
317300
pitch: 1.5,
318301
rate: 0.8,
319302
});
320303

321304
// Track events specific to this utterance
322305
Speech.onProgress(({id: eventId, location, length}) => {
323-
if (eventId === id) {
306+
if (eventId === id2) {
324307
console.log(`Progress: ${location}/${length}`);
325308
}
326309
});
327310
```
328311

329312
---
330313

314+
### Speaking Text with Custom Options (Deprecated)
315+
316+
Override global options for a specific utterance.
317+
318+
**API Definition:**
319+
320+
```ts
321+
Speech.speakWithOptions(text: string, options: VoiceOptions): Promise<string>
322+
```
323+
324+
**Notes:**
325+
326+
- Deprecated. Use `Speech.speak(text, options)` instead.
327+
328+
---
329+
331330
### Controlling Speech
332331

333332
#### **Stop Speech**

src/Speech.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,31 @@ export default class Speech {
133133
return TurboSpeech.isSpeaking();
134134
}
135135
/**
136-
* Speaks text using current global options
136+
* Speaks text using current global options, or per-utterance options if provided.
137137
* @param text - The text to synthesize
138+
* @param options - Optional voice options overriding global settings for this utterance
138139
* @returns Promise<string> Resolves with utterance ID when the utterance is queued
139140
* @throws If text is null or undefined
140141
* @example
141142
* const id = await Speech.speak('Hello, world!');
143+
* // Or with per-utterance options:
144+
* const id2 = await Speech.speak('Hello!', { pitch: 1.5, rate: 0.8 });
142145
* // Later, use this ID to track events:
143146
* Speech.onFinish(({id: eventId}) => {
144147
* if (eventId === id) console.log('My speech finished');
145148
* });
146149
*/
147-
public static speak(text: string): Promise<string> {
150+
public static speak(text: string): Promise<string>;
151+
public static speak(text: string, options: VoiceOptions): Promise<string>;
152+
public static speak(text: string, options?: VoiceOptions): Promise<string> {
153+
if (options !== undefined) {
154+
return TurboSpeech.speakWithOptions(text, options);
155+
}
148156
return TurboSpeech.speak(text);
149157
}
150158
/**
151159
* Speaks text with custom options for this utterance only. Uses global options for any settings not provided.
160+
* @deprecated Use `Speech.speak(text, options)` instead.
152161
* @param text - The text to synthesize
153162
* @param options - Voice options overriding global settings
154163
* @returns Promise<string> Resolves with utterance ID when the utterance is queued

0 commit comments

Comments
 (0)