Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTS fixes and Readme Updates #43

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/audio-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"deploy": "gh-pages -d dist"
},
"dependencies": {
"@browserai/browserai": "^1.0.13",
"@browserai/browserai": "^1.0.16",
"@emotion/styled": "^11.14.0",
"@huggingface/transformers": "^3.2.4",
"@mlc-ai/web-llm": "^0.2.77",
Expand Down
6 changes: 4 additions & 2 deletions examples/audio-demo/src/components/ChatInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,9 @@ export default function ChatInterface() {
const audioLoadStart = performance.now();
setStatus('Loading audio model...');
try {
await audioAIRef.loadModel('whisper-tiny-en');
await audioAIRef.loadModel('whisper-tiny-en', {
device: 'webgpu'
});
console.log('Audio model loaded successfully');
} catch (error) {
console.error('Error loading audio model:', error);
Expand All @@ -733,7 +735,7 @@ export default function ChatInterface() {
const ttsLoadStart = performance.now();
setStatus('Loading TTS model...');
try {
await ttsAIRef.loadModel('speecht5-tts');
await ttsAIRef.loadModel('kokoro-tts');
console.log('TTS model loaded successfully');
} catch (error) {
console.error('Error loading TTS model:', error);
Expand Down
2 changes: 1 addition & 1 deletion examples/tts-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@browserai/browserai": "^1.0.15",
"@browserai/browserai": "^1.0.16",
"@emotion/styled": "^11.14.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@browserai/browserai",
"version": "1.0.15",
"version": "1.0.16",
"private": false,
"description": "A library for running AI models directly in the browser",
"main": "dist/index.js",
Expand Down
13 changes: 10 additions & 3 deletions src/libs/transformers/backends/onnx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export async function createInferenceSession(
session_options: any,
session_config: any
) {
const preferredBackend = session_config.backend || 'webgpu';
if (wasmInitPromise) {
// A previous session has already initialized the WASM runtime
// so we wait for it to resolve before creating this new session.
Expand Down Expand Up @@ -142,23 +141,31 @@ if (ONNX_ENV?.wasm) {
// https://onnxruntime.ai/docs/api/js/interfaces/Env.WebAssemblyFlags.html#wasmPaths
// We use remote wasm files by default to make it easier for newer users.
// In practice, users should probably self-host the necessary .wasm files.
ONNX_ENV.wasm.wasmPaths = `https://cdn.jsdelivr.net/npm/@huggingface/transformers@${env.version}/dist/`;

ONNX_ENV.wasm.wasmPaths = {
wasm: `https://cdn.jsdelivr.net/npm/@huggingface/transformers@${env.version}/dist/ort-wasm-simd-threaded.jsep.wasm`,
mjs: `https://cdn.jsdelivr.net/npm/@huggingface/transformers@${env.version}/dist/ort-wasm-simd-threaded.jsep.mjs`,
};
sauravpanda marked this conversation as resolved.
Show resolved Hide resolved
// https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.2.4/dist/ort-wasm-simd-threaded.jsep.wasm
// console.log('ONNX_ENV.wasm.wasmPaths', ONNX_ENV.wasm.wasmPaths);
console.log('ONNX_ENV.wasm.wasmPaths', ONNX_ENV.wasm.wasmPaths);
// TODO: Add support for loading WASM files from cached buffer when we upgrade to onnxruntime-web@1.19.0
// https://github.com/microsoft/onnxruntime/pull/21534

// Users may wish to proxy the WASM backend to prevent the UI from freezing,
// However, this is not necessary when using WebGPU, so we default to false.
ONNX_ENV.wasm.proxy = false;

// Disable threading to avoid potential issues
ONNX_ENV.wasm.numThreads = 1;
sauravpanda marked this conversation as resolved.
Show resolved Hide resolved

// https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated
if (typeof crossOriginIsolated === 'undefined' || !crossOriginIsolated) {
ONNX_ENV.wasm.numThreads = 1;
}
}

if (ONNX_ENV?.webgpu) {
console.log('ONNX_ENV.webgpu', ONNX_ENV.webgpu);
ONNX_ENV.webgpu.powerPreference = 'high-performance';
}

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion src/libs/transformers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import path from 'path';
import url from 'url';

const VERSION = '3.2.4';
const VERSION = '3.3.1';

// Check if various APIs are available (depends on environment)
const IS_BROWSER_ENV = typeof window !== 'undefined' && typeof window.document !== 'undefined';
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading