Skip to content

Commit 5b558c1

Browse files
committed
v1.0.0 release
1 parent 77fa8c1 commit 5b558c1

19 files changed

+565
-195
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
test-results
26+
playwright-report

README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/diffusion-studio/ffmpeg-js/graphs/commit-activity)
2+
[![Website shields.io](https://img.shields.io/website-up-down-green-red/http/shields.io.svg)](https://diffusion.studio)
3+
[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/n3mpzfejAb)
4+
[![GitHub license](https://badgen.net/github/license/Naereen/Strapdown.js)](https://github.com/diffusion-studio/ffmpeg-js/blob/main/LICENSE)
5+
[![TypeScript](https://badgen.net/badge/icon/typescript?icon=typescript&label)](https://typescriptlang.org)
6+
7+
# Use VITS models in the browser powered by the [ONNX Runtime](https://onnxruntime.ai/)
8+
9+
A big shout-out goes to [Rhasspy Piper](https://github.com/rhasspy/piper), who open-sourced all the currently available models (MIT License) and to [@jozefchutka](https://github.com/jozefchutka) who came up with the wasm build steps.
10+
11+
## Usage
12+
First of all, you need to install the library:
13+
```bash
14+
npm i --save @diffusionstudio/vits-web
15+
```
16+
17+
Then you're able to import the library like this (ES only)
18+
```typescript
19+
import * as tts from '@diffusionstudio/vits-web';
20+
21+
// Hint: onnxruntime-web is a peer dependency
22+
```
23+
24+
Now you can start synthesizing speech!
25+
```typescript
26+
const wav = await tts.predict({
27+
text: "Text to speech in the browser is amazing!",
28+
voiceId: 'en_US-hfc_female-medium',
29+
});
30+
31+
// available in Web Worker
32+
33+
const audio = new Audio();
34+
audio.src = URL.createObjectURL(wav);
35+
audio.play();
36+
```
37+
38+
With the initial run of the predict function you will download the model which will then be stored in your [Origin private file system](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system). You can also do this manually in advance *(recommended)*, as follows:
39+
```typescript
40+
await tts.download('en_US-hfc_female-medium', (progress) => {
41+
console.log(`Downloading ${progress.url} - ${Math.round(progress.loaded * 100 / progress.total)}%`);
42+
});
43+
```
44+
45+
The predict function also accepts a download progress callback as the second argument (`tts.predict(..., console.log)`). <br>
46+
47+
If you want to know which models have already been stored, do the following
48+
```typescript
49+
console.log(await tts.stored());
50+
51+
// will log ['en_US-hfc_female-medium']
52+
```
53+
54+
You can remove models from opfs by calling
55+
```typescript
56+
await tts.remove('en_US-hfc_female-medium');
57+
58+
// alternatively delete all
59+
60+
await tts.flush();
61+
```
62+
63+
And last but not least use this snippet if you would like to retrieve all available voices:
64+
```typescript
65+
console.log(await tts.voices());
66+
67+
// Hint: the key can be used as voiceId
68+
```
69+
70+
### **That's it!** Happy coding :)

package-lock.json

+101-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@
4444
"scripts": {
4545
"dev": "vite",
4646
"build": "rm -r -f ./dist && tsc && vite build",
47-
"preview": "vite preview"
47+
"preview": "vite preview",
48+
"test": "npx playwright test --project=chromium"
4849
},
4950
"devDependencies": {
5051
"typescript": "^5.2.2",
5152
"vite": "^5.3.1",
52-
"vite-plugin-dts": "^3.9.1"
53+
"vite-plugin-dts": "^3.9.1",
54+
"@playwright/test": "^1.35.1"
5355
},
54-
"dependencies": {
56+
"peerDependencies": {
5557
"onnxruntime-web": "^1.18.0"
5658
}
5759
}

0 commit comments

Comments
 (0)