File size: 2,316 Bytes
4a58e48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { chromium } from '@playwright/test';
const device = process.argv[2] || 'wasm';
const b = await chromium.launch({ channel: 'chrome', args: ['--enable-unsafe-webgpu', '--enable-features=Vulkan', '--autoplay-policy=no-user-gesture-required'] });
const p = await (await b.newContext()).newPage();
p.on('pageerror', e => console.log('pageerror', e.message));
p.on('console', m => { if (m.type() === 'error' || m.type()==='warning') console.log(m.type(), m.text().slice(0,160)); });
await p.goto('http://localhost:4173/');
await p.evaluate(([d,t,dt]) => { localStorage.setItem('earshelf.device', d); if (t) localStorage.setItem('earshelf.threads', t); if (dt) localStorage.setItem('earshelf.dtype', dt); }, [device, process.argv[3] || '', process.argv[4] || '']);
console.log(await p.evaluate(() => ({ iso: crossOriginIsolated, gpu: !!navigator.gpu, cores: navigator.hardwareConcurrency })));
// make natural the chosen voice
await p.evaluate(async () => { const r = indexedDB.open('earshelf', 1); await new Promise(res => r.onsuccess = res); });
const t0 = Date.now();
await p.click('#sample');
await p.waitForSelector('#player:not([hidden])');
// switch to natural voice explicitly via the voice sheet
await p.click('#voice-btn');
await p.click('.voice-opt >> text=Heart');
await p.keyboard.press('Escape');
const t1 = Date.now();
await p.waitForFunction(() => window.__earshelf.engine.model.s === 'ready' || window.__earshelf.engine.model.s === 'error', null, { timeout: 600000 });
const m = await p.evaluate(() => window.__earshelf.engine.model);
console.log('model', m, 'load s', (Date.now() - t1) / 1000);
await p.click('#play'); // ensure playing
const t2 = Date.now();
const playing = await p.evaluate(() => window.__earshelf.engine.playing);
if (!playing) await p.click('#play');
await p.waitForFunction(() => { const a = [...document.querySelectorAll('audio')]; return true; });
// measure: wait until sentence index advances 3 times
await p.waitForFunction(() => window.__earshelf.engine.index >= 3, null, { timeout: 300000 });
console.log('3 sentences spoken in s', (Date.now() - t2) / 1000);
const st = await p.evaluate(() => window.__earshelf.engine.stats);
console.log('stats', JSON.stringify(st), 'RTF', (st.reduce((a,x)=>a+x.genMs,0)/st.reduce((a,x)=>a+x.audioMs,0)).toFixed(3));
await b.close();