-
Notifications
You must be signed in to change notification settings - Fork 281
Expand file tree
/
Copy pathapp.js
More file actions
77 lines (66 loc) · 2.38 KB
/
app.js
File metadata and controls
77 lines (66 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// <complete_code>
// <imports>
import { FoundryLocalManager } from 'foundry-local-sdk';
// </imports>
// Initialize the Foundry Local SDK
console.log('Initializing Foundry Local SDK...');
// <init>
const manager = FoundryLocalManager.create({
appName: 'foundry_local_samples',
logLevel: 'info'
});
// </init>
console.log('✓ SDK initialized successfully');
// Download and register all execution providers.
let currentEp = '';
await manager.downloadAndRegisterEps((epName, percent) => {
if (epName !== currentEp) {
if (currentEp !== '') process.stdout.write('\n');
currentEp = epName;
}
process.stdout.write(`\r ${epName.padEnd(30)} ${percent.toFixed(1).padStart(5)}%`);
});
if (currentEp !== '') process.stdout.write('\n');
// <model_setup>
// Get the model object
const modelAlias = 'whisper-tiny'; // Using an available model from the list above
let model = await manager.catalog.getModel(modelAlias);
console.log(`Using model: ${model.id}`);
// Download the model
console.log(`\nDownloading model ${modelAlias}...`);
await model.download((progress) => {
process.stdout.write(`\rDownloading... ${progress.toFixed(2)}%`);
});
console.log('\n✓ Model downloaded');
// Load the model
console.log(`\nLoading model ${modelAlias}...`);
await model.load();
console.log('✓ Model loaded');
// </model_setup>
// <transcription>
// Create audio client
console.log('\nCreating audio client...');
const audioClient = model.createAudioClient();
console.log('✓ Audio client created');
// Example audio transcription
const audioFile = process.argv[2] || './Recording.mp3';
console.log(`\nTranscribing ${audioFile}...`);
const transcription = await audioClient.transcribe(audioFile);
console.log('\nAudio transcription result:');
console.log(transcription.text);
console.log('✓ Audio transcription completed');
// Same example but with streaming transcription using async iteration
console.log('\nTesting streaming audio transcription...');
for await (const result of audioClient.transcribeStreaming(audioFile)) {
// Output the intermediate transcription results as they are received without line ending
process.stdout.write(result.text);
}
console.log('\n✓ Streaming transcription completed');
// </transcription>
// <cleanup>
// Unload the model
console.log('Unloading model...');
await model.unload();
console.log(`✓ Model unloaded`);
// </cleanup>
// </complete_code>