v70: тире между слогами + onclick — playHistorySyl из IndexedDB
This commit is contained in:
+15
-5
@@ -38,15 +38,12 @@ let _currentBlob = null;
|
||||
let _currentSylBuf = null;
|
||||
|
||||
async function playSyllable(sylIdx, total) {
|
||||
console.log('[SYL] click', sylIdx, '/', total, 'blob=', !!_currentBlob);
|
||||
if (!_currentBlob) return;
|
||||
try {
|
||||
const ctx = await getAudioCtx();
|
||||
console.log('[SYL] ctx.state=', ctx.state);
|
||||
if (!_currentSylBuf) {
|
||||
const ab = await _currentBlob.arrayBuffer();
|
||||
_currentSylBuf = await ctx.decodeAudioData(ab);
|
||||
console.log('[SYL] decoded', _currentSylBuf.duration.toFixed(1) + 's');
|
||||
}
|
||||
const dur = _currentSylBuf.duration;
|
||||
const start = (dur / total) * sylIdx;
|
||||
@@ -55,6 +52,19 @@ async function playSyllable(sylIdx, total) {
|
||||
src.buffer = _currentSylBuf;
|
||||
src.connect(ctx.destination);
|
||||
src.start(0, start, len);
|
||||
console.log('[SYL] playing', start.toFixed(2) + 's-' + (start+len).toFixed(2) + 's');
|
||||
} catch(e) { console.log('[SYL] ERR', e); }
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
// Проигрывание слога из истории (загрузка blob из IndexedDB)
|
||||
async function playHistorySyl(recId, sylIdx, total) {
|
||||
try {
|
||||
const db = await openRecDB();
|
||||
const tx = db.transaction('recs', 'readonly');
|
||||
const store = tx.objectStore('recs');
|
||||
const rec = await new Promise(r => { const req = store.get(recId); req.onsuccess = () => r(req.result); });
|
||||
if (!rec?.blob) return;
|
||||
_currentBlob = rec.blob;
|
||||
_currentSylBuf = null;
|
||||
await playSyllable(sylIdx, total);
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user