@astrake/producer-voice 0.0.0-stage → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,240 @@
1
+ interface VoiceSynthesisRequest {
2
+ id?: string;
3
+ text: string;
4
+ voice?: string;
5
+ locale?: string;
6
+ speed?: number;
7
+ style?: string;
8
+ wavPath?: string;
9
+ lexicons?: PronunciationLexiconMap;
10
+ outWavPath: string;
11
+ }
12
+ interface WordTiming {
13
+ word: string;
14
+ startMs: number;
15
+ endMs: number;
16
+ }
17
+ interface VoiceProvenance {
18
+ providerId: string;
19
+ voice: string;
20
+ locale: string;
21
+ sourceSampleRateHz: number;
22
+ isSynthetic: boolean;
23
+ isRoboticFallback: boolean;
24
+ zcrStd?: number;
25
+ cacheHit: boolean;
26
+ }
27
+ interface VoiceSynthesisResult {
28
+ wavPath: string;
29
+ durationMs: number;
30
+ words: WordTiming[];
31
+ provenance: VoiceProvenance;
32
+ }
33
+ interface VoiceProvider {
34
+ readonly id: string;
35
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
36
+ }
37
+ interface CaptionEntry {
38
+ id: string;
39
+ speaker?: string;
40
+ text: string;
41
+ startMs: number;
42
+ endMs: number;
43
+ words: WordTiming[];
44
+ }
45
+ interface LexiconEntry {
46
+ spoken?: string;
47
+ ipa?: string;
48
+ }
49
+ type PronunciationLexiconMap = Record<string, Record<string, LexiconEntry>>;
50
+ declare const DEFAULT_NEURAL_VOICES: Record<string, string>;
51
+ /** @deprecated Use `DEFAULT_NEURAL_VOICES`. */
52
+ declare const EDGE_DEFAULT_VOICES: Record<string, string>;
53
+ declare function resolveNeuralVoiceName(locale?: string, voice?: string): string;
54
+ /** @deprecated Use `resolveNeuralVoiceName`. */
55
+ declare const resolveEdgeVoiceName: typeof resolveNeuralVoiceName;
56
+
57
+ declare class VoiceDiskCache {
58
+ readonly cacheDir: string;
59
+ constructor(cacheDir?: string);
60
+ computeKey(payload: Record<string, unknown>): string;
61
+ get(key: string, outWavPath: string): Promise<VoiceSynthesisResult | null>;
62
+ put(key: string, outWavPath: string, durationMs: number, words: WordTiming[], provenance: VoiceProvenance): Promise<void>;
63
+ }
64
+
65
+ declare function emitCaptionsSrt(entries: CaptionEntry[]): string;
66
+ declare function emitCaptionsVtt(entries: CaptionEntry[]): string;
67
+
68
+ interface WavHeaderInfo {
69
+ sampleRateHz: number;
70
+ channels: number;
71
+ bitsPerSample: number;
72
+ durationMs: number;
73
+ isSyntheticTag: boolean;
74
+ }
75
+ declare function estimateWordTimings(text: string, durationMs: number): WordTiming[];
76
+ declare function readWavHeaderInfo(wavBytes: Buffer): WavHeaderInfo;
77
+ declare function readWavDurationMs(wavBytes: Buffer): number;
78
+ /**
79
+ * Computes windowed zero-crossing-rate standard deviation on 16-bit PCM WAV bytes.
80
+ * Pure synthetic tones / buzzes exhibit near-zero ZCR variance (< 0.008), whereas natural
81
+ * human/neural speech modulates across voiced vowels and sibilants (>= 0.02).
82
+ */
83
+ declare function computeAudioZcrStd(wavBytes: Buffer): number | undefined;
84
+ declare function probeSourceAudioSampleRate(srcPath: string): {
85
+ sampleRateHz: number;
86
+ isSyntheticTag: boolean;
87
+ };
88
+ declare function writePcm16MonoWav(samples: Int16Array, sampleRate?: number, opts?: {
89
+ softwareTag?: string;
90
+ }): Buffer;
91
+ declare function transcodeAudioTo48kMonoWav(srcPath: string, outWavPath: string): void;
92
+ declare function transcodeAudioTo48kStereoWav(srcPath: string, outWavPath: string): void;
93
+
94
+ declare function escapeXml(str: string): string;
95
+ declare function applyPronunciationLexicon(text: string, locale: string, lexicons?: PronunciationLexiconMap): {
96
+ spokenText: string;
97
+ ssmlFragment: string;
98
+ };
99
+
100
+ interface AzureSpeechOptions {
101
+ apiKey?: string;
102
+ region?: string;
103
+ endpoint?: string;
104
+ cacheDir?: string;
105
+ timeoutMs?: number;
106
+ }
107
+ declare class AzureSpeechVoiceProvider implements VoiceProvider {
108
+ readonly id = "azure-speech";
109
+ private readonly apiKey;
110
+ private readonly region;
111
+ private readonly endpoint;
112
+ private readonly cache;
113
+ private readonly timeoutMs;
114
+ constructor(options?: AzureSpeechOptions);
115
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
116
+ }
117
+
118
+ declare class CommandVoiceProvider implements VoiceProvider {
119
+ private readonly command;
120
+ private readonly args;
121
+ readonly id: string;
122
+ constructor(command: string, args?: string[]);
123
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
124
+ }
125
+ interface LocalCliTtsOptions {
126
+ command?: string;
127
+ modelPath?: string;
128
+ cacheDir?: string;
129
+ }
130
+ declare class KokoroCliVoiceProvider implements VoiceProvider {
131
+ readonly id = "kokoro-cli";
132
+ private readonly command;
133
+ private readonly cache;
134
+ constructor(options?: LocalCliTtsOptions);
135
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
136
+ }
137
+ declare class PiperCliVoiceProvider implements VoiceProvider {
138
+ readonly id = "piper-cli";
139
+ private readonly command;
140
+ private readonly modelPath;
141
+ private readonly cache;
142
+ constructor(options?: LocalCliTtsOptions);
143
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
144
+ }
145
+
146
+ interface ElevenLabsOptions {
147
+ apiKey?: string;
148
+ voiceId?: string;
149
+ modelId?: string;
150
+ outputFormat?: string;
151
+ endpointBase?: string;
152
+ cacheDir?: string;
153
+ timeoutMs?: number;
154
+ }
155
+ declare class ElevenLabsVoiceProvider implements VoiceProvider {
156
+ readonly id = "elevenlabs";
157
+ private readonly apiKey;
158
+ private readonly defaultVoiceId;
159
+ private readonly modelId;
160
+ private readonly outputFormat;
161
+ private readonly endpointBase;
162
+ private readonly cache;
163
+ private readonly timeoutMs;
164
+ constructor(options?: ElevenLabsOptions);
165
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
166
+ }
167
+
168
+ interface GeminiTtsOptions {
169
+ apiKey?: string;
170
+ model?: string;
171
+ endpoint?: string;
172
+ cacheDir?: string;
173
+ timeoutMs?: number;
174
+ }
175
+ declare class GeminiTtsVoiceProvider implements VoiceProvider {
176
+ readonly id = "gemini-tts";
177
+ private readonly apiKey;
178
+ private readonly model;
179
+ private readonly endpoint;
180
+ private readonly cache;
181
+ private readonly timeoutMs;
182
+ constructor(options?: GeminiTtsOptions);
183
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
184
+ }
185
+
186
+ declare class PreRecordedVoiceProvider implements VoiceProvider {
187
+ readonly id = "prerecorded";
188
+ private readonly pathMap;
189
+ constructor(entries?: Record<string, string>);
190
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
191
+ }
192
+
193
+ interface SarvamBulbulOptions {
194
+ apiKey?: string;
195
+ model?: string;
196
+ endpoint?: string;
197
+ cacheDir?: string;
198
+ timeoutMs?: number;
199
+ }
200
+ declare class SarvamBulbulVoiceProvider implements VoiceProvider {
201
+ readonly id = "sarvam-bulbul";
202
+ private readonly apiKey;
203
+ private readonly model;
204
+ private readonly endpoint;
205
+ private readonly cache;
206
+ private readonly timeoutMs;
207
+ constructor(options?: SarvamBulbulOptions);
208
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
209
+ }
210
+
211
+ declare class OsNativeVoiceProvider implements VoiceProvider {
212
+ private readonly options;
213
+ readonly id = "os-native";
214
+ constructor(options?: {
215
+ allowRoboticFallback?: boolean;
216
+ });
217
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
218
+ }
219
+ declare class SyntheticToneVoiceProvider implements VoiceProvider {
220
+ readonly id = "synthetic-tone";
221
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
222
+ }
223
+
224
+ /**
225
+ * Removed in v0.3.0 because the undocumented Bing Edge ReadAloud WebSocket enforces rotating DRM
226
+ * headers and returns HTTP 403. Use AzureSpeechVoiceProvider (500k free neural chars/month F0 tier)
227
+ * or GeminiTtsVoiceProvider / SarvamBulbulVoiceProvider / ElevenLabsVoiceProvider / KokoroCliVoiceProvider.
228
+ */
229
+ declare class EdgeNeuralVoiceProvider implements VoiceProvider {
230
+ readonly options?: Record<string, unknown> | undefined;
231
+ readonly id = "edge-neural-removed";
232
+ constructor(options?: Record<string, unknown> | undefined);
233
+ synthesize(): Promise<never>;
234
+ }
235
+ declare function createAutoVoiceProvider(opts?: {
236
+ provider?: string;
237
+ cacheDir?: string;
238
+ }): VoiceProvider;
239
+
240
+ export { type AzureSpeechOptions, AzureSpeechVoiceProvider, type CaptionEntry, CommandVoiceProvider, DEFAULT_NEURAL_VOICES, EDGE_DEFAULT_VOICES, EdgeNeuralVoiceProvider, type ElevenLabsOptions, ElevenLabsVoiceProvider, type GeminiTtsOptions, GeminiTtsVoiceProvider, KokoroCliVoiceProvider, type LexiconEntry, type LocalCliTtsOptions, OsNativeVoiceProvider, PiperCliVoiceProvider, PreRecordedVoiceProvider, type PronunciationLexiconMap, type SarvamBulbulOptions, SarvamBulbulVoiceProvider, SyntheticToneVoiceProvider, VoiceDiskCache, type VoiceProvenance, type VoiceProvider, type VoiceSynthesisRequest, type VoiceSynthesisResult, type WavHeaderInfo, type WordTiming, applyPronunciationLexicon, computeAudioZcrStd, createAutoVoiceProvider, emitCaptionsSrt, emitCaptionsVtt, escapeXml, estimateWordTimings, probeSourceAudioSampleRate, readWavDurationMs, readWavHeaderInfo, resolveEdgeVoiceName, resolveNeuralVoiceName, transcodeAudioTo48kMonoWav, transcodeAudioTo48kStereoWav, writePcm16MonoWav };
@@ -0,0 +1,240 @@
1
+ interface VoiceSynthesisRequest {
2
+ id?: string;
3
+ text: string;
4
+ voice?: string;
5
+ locale?: string;
6
+ speed?: number;
7
+ style?: string;
8
+ wavPath?: string;
9
+ lexicons?: PronunciationLexiconMap;
10
+ outWavPath: string;
11
+ }
12
+ interface WordTiming {
13
+ word: string;
14
+ startMs: number;
15
+ endMs: number;
16
+ }
17
+ interface VoiceProvenance {
18
+ providerId: string;
19
+ voice: string;
20
+ locale: string;
21
+ sourceSampleRateHz: number;
22
+ isSynthetic: boolean;
23
+ isRoboticFallback: boolean;
24
+ zcrStd?: number;
25
+ cacheHit: boolean;
26
+ }
27
+ interface VoiceSynthesisResult {
28
+ wavPath: string;
29
+ durationMs: number;
30
+ words: WordTiming[];
31
+ provenance: VoiceProvenance;
32
+ }
33
+ interface VoiceProvider {
34
+ readonly id: string;
35
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
36
+ }
37
+ interface CaptionEntry {
38
+ id: string;
39
+ speaker?: string;
40
+ text: string;
41
+ startMs: number;
42
+ endMs: number;
43
+ words: WordTiming[];
44
+ }
45
+ interface LexiconEntry {
46
+ spoken?: string;
47
+ ipa?: string;
48
+ }
49
+ type PronunciationLexiconMap = Record<string, Record<string, LexiconEntry>>;
50
+ declare const DEFAULT_NEURAL_VOICES: Record<string, string>;
51
+ /** @deprecated Use `DEFAULT_NEURAL_VOICES`. */
52
+ declare const EDGE_DEFAULT_VOICES: Record<string, string>;
53
+ declare function resolveNeuralVoiceName(locale?: string, voice?: string): string;
54
+ /** @deprecated Use `resolveNeuralVoiceName`. */
55
+ declare const resolveEdgeVoiceName: typeof resolveNeuralVoiceName;
56
+
57
+ declare class VoiceDiskCache {
58
+ readonly cacheDir: string;
59
+ constructor(cacheDir?: string);
60
+ computeKey(payload: Record<string, unknown>): string;
61
+ get(key: string, outWavPath: string): Promise<VoiceSynthesisResult | null>;
62
+ put(key: string, outWavPath: string, durationMs: number, words: WordTiming[], provenance: VoiceProvenance): Promise<void>;
63
+ }
64
+
65
+ declare function emitCaptionsSrt(entries: CaptionEntry[]): string;
66
+ declare function emitCaptionsVtt(entries: CaptionEntry[]): string;
67
+
68
+ interface WavHeaderInfo {
69
+ sampleRateHz: number;
70
+ channels: number;
71
+ bitsPerSample: number;
72
+ durationMs: number;
73
+ isSyntheticTag: boolean;
74
+ }
75
+ declare function estimateWordTimings(text: string, durationMs: number): WordTiming[];
76
+ declare function readWavHeaderInfo(wavBytes: Buffer): WavHeaderInfo;
77
+ declare function readWavDurationMs(wavBytes: Buffer): number;
78
+ /**
79
+ * Computes windowed zero-crossing-rate standard deviation on 16-bit PCM WAV bytes.
80
+ * Pure synthetic tones / buzzes exhibit near-zero ZCR variance (< 0.008), whereas natural
81
+ * human/neural speech modulates across voiced vowels and sibilants (>= 0.02).
82
+ */
83
+ declare function computeAudioZcrStd(wavBytes: Buffer): number | undefined;
84
+ declare function probeSourceAudioSampleRate(srcPath: string): {
85
+ sampleRateHz: number;
86
+ isSyntheticTag: boolean;
87
+ };
88
+ declare function writePcm16MonoWav(samples: Int16Array, sampleRate?: number, opts?: {
89
+ softwareTag?: string;
90
+ }): Buffer;
91
+ declare function transcodeAudioTo48kMonoWav(srcPath: string, outWavPath: string): void;
92
+ declare function transcodeAudioTo48kStereoWav(srcPath: string, outWavPath: string): void;
93
+
94
+ declare function escapeXml(str: string): string;
95
+ declare function applyPronunciationLexicon(text: string, locale: string, lexicons?: PronunciationLexiconMap): {
96
+ spokenText: string;
97
+ ssmlFragment: string;
98
+ };
99
+
100
+ interface AzureSpeechOptions {
101
+ apiKey?: string;
102
+ region?: string;
103
+ endpoint?: string;
104
+ cacheDir?: string;
105
+ timeoutMs?: number;
106
+ }
107
+ declare class AzureSpeechVoiceProvider implements VoiceProvider {
108
+ readonly id = "azure-speech";
109
+ private readonly apiKey;
110
+ private readonly region;
111
+ private readonly endpoint;
112
+ private readonly cache;
113
+ private readonly timeoutMs;
114
+ constructor(options?: AzureSpeechOptions);
115
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
116
+ }
117
+
118
+ declare class CommandVoiceProvider implements VoiceProvider {
119
+ private readonly command;
120
+ private readonly args;
121
+ readonly id: string;
122
+ constructor(command: string, args?: string[]);
123
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
124
+ }
125
+ interface LocalCliTtsOptions {
126
+ command?: string;
127
+ modelPath?: string;
128
+ cacheDir?: string;
129
+ }
130
+ declare class KokoroCliVoiceProvider implements VoiceProvider {
131
+ readonly id = "kokoro-cli";
132
+ private readonly command;
133
+ private readonly cache;
134
+ constructor(options?: LocalCliTtsOptions);
135
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
136
+ }
137
+ declare class PiperCliVoiceProvider implements VoiceProvider {
138
+ readonly id = "piper-cli";
139
+ private readonly command;
140
+ private readonly modelPath;
141
+ private readonly cache;
142
+ constructor(options?: LocalCliTtsOptions);
143
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
144
+ }
145
+
146
+ interface ElevenLabsOptions {
147
+ apiKey?: string;
148
+ voiceId?: string;
149
+ modelId?: string;
150
+ outputFormat?: string;
151
+ endpointBase?: string;
152
+ cacheDir?: string;
153
+ timeoutMs?: number;
154
+ }
155
+ declare class ElevenLabsVoiceProvider implements VoiceProvider {
156
+ readonly id = "elevenlabs";
157
+ private readonly apiKey;
158
+ private readonly defaultVoiceId;
159
+ private readonly modelId;
160
+ private readonly outputFormat;
161
+ private readonly endpointBase;
162
+ private readonly cache;
163
+ private readonly timeoutMs;
164
+ constructor(options?: ElevenLabsOptions);
165
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
166
+ }
167
+
168
+ interface GeminiTtsOptions {
169
+ apiKey?: string;
170
+ model?: string;
171
+ endpoint?: string;
172
+ cacheDir?: string;
173
+ timeoutMs?: number;
174
+ }
175
+ declare class GeminiTtsVoiceProvider implements VoiceProvider {
176
+ readonly id = "gemini-tts";
177
+ private readonly apiKey;
178
+ private readonly model;
179
+ private readonly endpoint;
180
+ private readonly cache;
181
+ private readonly timeoutMs;
182
+ constructor(options?: GeminiTtsOptions);
183
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
184
+ }
185
+
186
+ declare class PreRecordedVoiceProvider implements VoiceProvider {
187
+ readonly id = "prerecorded";
188
+ private readonly pathMap;
189
+ constructor(entries?: Record<string, string>);
190
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
191
+ }
192
+
193
+ interface SarvamBulbulOptions {
194
+ apiKey?: string;
195
+ model?: string;
196
+ endpoint?: string;
197
+ cacheDir?: string;
198
+ timeoutMs?: number;
199
+ }
200
+ declare class SarvamBulbulVoiceProvider implements VoiceProvider {
201
+ readonly id = "sarvam-bulbul";
202
+ private readonly apiKey;
203
+ private readonly model;
204
+ private readonly endpoint;
205
+ private readonly cache;
206
+ private readonly timeoutMs;
207
+ constructor(options?: SarvamBulbulOptions);
208
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
209
+ }
210
+
211
+ declare class OsNativeVoiceProvider implements VoiceProvider {
212
+ private readonly options;
213
+ readonly id = "os-native";
214
+ constructor(options?: {
215
+ allowRoboticFallback?: boolean;
216
+ });
217
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
218
+ }
219
+ declare class SyntheticToneVoiceProvider implements VoiceProvider {
220
+ readonly id = "synthetic-tone";
221
+ synthesize(req: VoiceSynthesisRequest): Promise<VoiceSynthesisResult>;
222
+ }
223
+
224
+ /**
225
+ * Removed in v0.3.0 because the undocumented Bing Edge ReadAloud WebSocket enforces rotating DRM
226
+ * headers and returns HTTP 403. Use AzureSpeechVoiceProvider (500k free neural chars/month F0 tier)
227
+ * or GeminiTtsVoiceProvider / SarvamBulbulVoiceProvider / ElevenLabsVoiceProvider / KokoroCliVoiceProvider.
228
+ */
229
+ declare class EdgeNeuralVoiceProvider implements VoiceProvider {
230
+ readonly options?: Record<string, unknown> | undefined;
231
+ readonly id = "edge-neural-removed";
232
+ constructor(options?: Record<string, unknown> | undefined);
233
+ synthesize(): Promise<never>;
234
+ }
235
+ declare function createAutoVoiceProvider(opts?: {
236
+ provider?: string;
237
+ cacheDir?: string;
238
+ }): VoiceProvider;
239
+
240
+ export { type AzureSpeechOptions, AzureSpeechVoiceProvider, type CaptionEntry, CommandVoiceProvider, DEFAULT_NEURAL_VOICES, EDGE_DEFAULT_VOICES, EdgeNeuralVoiceProvider, type ElevenLabsOptions, ElevenLabsVoiceProvider, type GeminiTtsOptions, GeminiTtsVoiceProvider, KokoroCliVoiceProvider, type LexiconEntry, type LocalCliTtsOptions, OsNativeVoiceProvider, PiperCliVoiceProvider, PreRecordedVoiceProvider, type PronunciationLexiconMap, type SarvamBulbulOptions, SarvamBulbulVoiceProvider, SyntheticToneVoiceProvider, VoiceDiskCache, type VoiceProvenance, type VoiceProvider, type VoiceSynthesisRequest, type VoiceSynthesisResult, type WavHeaderInfo, type WordTiming, applyPronunciationLexicon, computeAudioZcrStd, createAutoVoiceProvider, emitCaptionsSrt, emitCaptionsVtt, escapeXml, estimateWordTimings, probeSourceAudioSampleRate, readWavDurationMs, readWavHeaderInfo, resolveEdgeVoiceName, resolveNeuralVoiceName, transcodeAudioTo48kMonoWav, transcodeAudioTo48kStereoWav, writePcm16MonoWav };