Skip to content

Commit 32f966c

Browse files
committed
build: sync deps for audio module skeleton
1 parent b094eda commit 32f966c

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"typescript": "^5.7.3"
3434
},
3535
"dependencies": {
36-
"@huggingface/transformers": "^3.3.3"
36+
"@huggingface/transformers": "^3.3.3",
37+
"phonemizer": "^1.2.1"
3738
}
3839
}

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TinyLM.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ProgressTracker } from './ProgressTracker';
77
import { WebGPUChecker } from './WebGPUChecker';
88
import { GenerationModule } from './GenerationModule';
99
import { EmbeddingsModule } from './EmbeddingsModule';
10+
import { AudioModule } from './AudioModule';
1011

1112
import {
1213
TinyLMOptions,
@@ -17,7 +18,9 @@ import {
1718
CompletionChunk,
1819
ModelLoadOptions,
1920
EmbeddingCreateOptions,
20-
EmbeddingResult
21+
EmbeddingResult,
22+
SpeechCreateOptions,
23+
SpeechResult
2124
} from './types';
2225

2326
/**
@@ -33,6 +36,7 @@ export class TinyLM {
3336
// Modules
3437
private generationModule: GenerationModule;
3538
private embeddingsModule: EmbeddingsModule;
39+
private audioModule: AudioModule;
3640

3741
// API structure
3842
readonly chat: {
@@ -46,13 +50,22 @@ export class TinyLM {
4650
create: (options: EmbeddingCreateOptions) => Promise<EmbeddingResult>;
4751
};
4852

53+
readonly audio: {
54+
speech: {
55+
create: (options: SpeechCreateOptions) => Promise<SpeechResult>;
56+
};
57+
};
58+
4959
readonly models: {
5060
load: (options: ModelLoadOptions) => Promise<any>;
5161
offload: (options: { model: string }) => Promise<boolean>;
5262
interrupt: () => boolean;
5363
reset: () => void;
5464
check: () => Promise<CapabilityInfo>;
5565
list: () => string[];
66+
loadTTS: (options: { model: string }) => Promise<boolean>;
67+
offloadTTS: (options: { model: string }) => Promise<boolean>;
68+
listTTS: () => string[];
5669
};
5770

5871
/**
@@ -79,6 +92,7 @@ export class TinyLM {
7992
// Initialize modules
8093
this.generationModule = new GenerationModule(this);
8194
this.embeddingsModule = new EmbeddingsModule(this);
95+
this.audioModule = new AudioModule(this);
8296

8397
// Create API structure similar to OpenAI
8498
this.chat = {
@@ -92,14 +106,23 @@ export class TinyLM {
92106
create: this.embeddingsModule.create.bind(this.embeddingsModule)
93107
};
94108

109+
this.audio = {
110+
speech: {
111+
create: this.audioModule.createSpeech.bind(this.audioModule)
112+
}
113+
};
114+
95115
// Model management API
96116
this.models = {
97117
load: this.generationModule.loadModel.bind(this.generationModule),
98118
offload: this.generationModule.offloadModel.bind(this.generationModule),
99119
interrupt: this.generationModule.interrupt.bind(this.generationModule),
100120
reset: this.generationModule.reset.bind(this.generationModule),
101121
check: this.checkCapabilities.bind(this),
102-
list: () => Array.from(this.generationModule.getModelRegistry().keys())
122+
list: () => Array.from(this.generationModule.getModelRegistry().keys()),
123+
loadTTS: this.audioModule.loadModel.bind(this.audioModule),
124+
offloadTTS: this.audioModule.offloadModel.bind(this.audioModule),
125+
listTTS: this.audioModule.getLoadedModels.bind(this.audioModule)
103126
};
104127
}
105128

@@ -173,6 +196,11 @@ export class TinyLM {
173196
: undefined
174197
});
175198

199+
await this.audioModule.init({
200+
ttsModels: options.ttsModels || [],
201+
lazyLoad: options.lazyLoad
202+
});
203+
176204
this.initialized = true;
177205
}
178206
return this;

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export { TinyLM } from './TinyLM';
88
// Export modules
99
export { GenerationModule } from './GenerationModule';
1010
export { EmbeddingsModule } from './EmbeddingsModule';
11+
export { AudioModule } from './AudioModule';
1112

1213
// Export utilities
1314
export { tryGarbageCollection, detectEnvironment } from './utils';
@@ -17,6 +18,7 @@ export { FileProgressTracker } from './FileProgressTracker';
1718
export { WebGPUChecker } from './WebGPUChecker';
1819
export { GenerationController, InterruptableStoppingCriteria } from './GenerationController';
1920
export { createStreamer } from './TextStreamHandler';
21+
export { TTSEngine } from './TTSEngine';
2022

2123
// Export type definitions
2224
export type {
@@ -40,6 +42,10 @@ export type {
4042
EmbeddingCreateOptions,
4143
EmbeddingResult,
4244

45+
// Audio types
46+
SpeechCreateOptions,
47+
SpeechResult,
48+
4349
// Model types
4450
ModelLoadOptions,
4551
InitOptions,

src/types.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,12 @@ export interface ModelLoadOptions {
254254
}
255255

256256
/**
257-
* Interface for model initialization options
257+
* Update InitOptions to include ttsModels
258258
*/
259259
export interface InitOptions {
260260
models?: string[];
261261
embeddingModels?: string[];
262+
ttsModels?: string[];
262263
lazyLoad?: boolean;
263264
[key: string]: any;
264265
}
@@ -290,3 +291,31 @@ export interface EmbeddingResult {
290291
total_tokens: number;
291292
};
292293
}
294+
295+
296+
/**
297+
* Interface for speech creation options
298+
*/
299+
export interface SpeechCreateOptions {
300+
model?: string;
301+
input: string;
302+
voice?: string;
303+
response_format?: 'mp3' | 'wav';
304+
speed?: number;
305+
[key: string]: any;
306+
}
307+
308+
/**
309+
* Interface for speech result
310+
*/
311+
export interface SpeechResult {
312+
id: string;
313+
object: string;
314+
created: number;
315+
model: string;
316+
audio: ArrayBuffer;
317+
content_type: string;
318+
_tinylm?: {
319+
time_ms: number;
320+
};
321+
}

0 commit comments

Comments
 (0)