v64: фикс playSyllable — await resume(), отладка, :active стиль
This commit is contained in:
+8
-4
@@ -28,9 +28,9 @@ function syllabifyPhrase(text) {
|
||||
|
||||
// ---------- AudioContext для проигрывания слогов ----------
|
||||
let _audioCtx = null;
|
||||
function getAudioCtx() {
|
||||
async function getAudioCtx() {
|
||||
if (!_audioCtx) _audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
if (_audioCtx.state === 'suspended') _audioCtx.resume();
|
||||
if (_audioCtx.state === 'suspended') await _audioCtx.resume();
|
||||
return _audioCtx;
|
||||
}
|
||||
|
||||
@@ -38,12 +38,15 @@ let _currentBlob = null;
|
||||
let _currentSylBuf = null;
|
||||
|
||||
async function playSyllable(sylIdx, total) {
|
||||
console.log('[SYL] click', sylIdx, '/', total, 'blob=', !!_currentBlob);
|
||||
if (!_currentBlob) return;
|
||||
const ctx = getAudioCtx();
|
||||
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;
|
||||
@@ -52,5 +55,6 @@ async function playSyllable(sylIdx, total) {
|
||||
src.buffer = _currentSylBuf;
|
||||
src.connect(ctx.destination);
|
||||
src.start(0, start, len);
|
||||
} catch(e) { console.log('playSyllable ERR', e); }
|
||||
console.log('[SYL] playing', start.toFixed(2) + 's-' + (start+len).toFixed(2) + 's');
|
||||
} catch(e) { console.log('[SYL] ERR', e); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user