Fix: voice clone mic null when not in call mode
Browse files- scripts/omni_o_web.html +18 -3
scripts/omni_o_web.html
CHANGED
|
@@ -511,6 +511,12 @@ function closeCloneModal() {
|
|
| 511 |
if(recMediaRec) { recMediaRec.stop(); recMediaRec = null }
|
| 512 |
}
|
| 513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
let recMediaRec = null, recChunks = []
|
| 515 |
function startRec() {
|
| 516 |
recChunks = []
|
|
@@ -518,11 +524,20 @@ function startRec() {
|
|
| 518 |
btn.textContent = 'Recording...'
|
| 519 |
btn.classList.add('recording')
|
| 520 |
try{
|
| 521 |
-
const
|
| 522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 523 |
recMediaRec.ondataavailable = e => { if(e.data.size) recChunks.push(e.data) }
|
| 524 |
recMediaRec.start()
|
| 525 |
-
}catch(e){ $('#cloneStatus').textContent = 'Record failed: '+e.message }
|
| 526 |
}
|
| 527 |
|
| 528 |
async function stopRec() {
|
|
|
|
| 511 |
if(recMediaRec) { recMediaRec.stop(); recMediaRec = null }
|
| 512 |
}
|
| 513 |
|
| 514 |
+
function resetRecBtn() {
|
| 515 |
+
const btn = $('#recBtn')
|
| 516 |
+
btn.textContent = 'Hold to Record'
|
| 517 |
+
btn.classList.remove('recording')
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
let recMediaRec = null, recChunks = []
|
| 521 |
function startRec() {
|
| 522 |
recChunks = []
|
|
|
|
| 524 |
btn.textContent = 'Recording...'
|
| 525 |
btn.classList.add('recording')
|
| 526 |
try{
|
| 527 |
+
const stream = mic ? new MediaStream(mic.getAudioTracks()) : null
|
| 528 |
+
if (!stream) {
|
| 529 |
+
navigator.mediaDevices.getUserMedia({audio:{echoCancellation:true,noiseSuppression:true}}).then(s => {
|
| 530 |
+
const r = new MediaRecorder(s, {mimeType:'audio/webm;codecs=opus'})
|
| 531 |
+
recMediaRec = r
|
| 532 |
+
r.ondataavailable = e => { if(e.data.size) recChunks.push(e.data) }
|
| 533 |
+
r.start()
|
| 534 |
+
}).catch(e => { $('#cloneStatus').textContent = 'Record failed: '+e.message; resetRecBtn() })
|
| 535 |
+
return
|
| 536 |
+
}
|
| 537 |
+
recMediaRec = new MediaRecorder(stream, {mimeType:'audio/webm;codecs=opus'})
|
| 538 |
recMediaRec.ondataavailable = e => { if(e.data.size) recChunks.push(e.data) }
|
| 539 |
recMediaRec.start()
|
| 540 |
+
}catch(e){ $('#cloneStatus').textContent = 'Record failed: '+e.message; resetRecBtn() }
|
| 541 |
}
|
| 542 |
|
| 543 |
async function stopRec() {
|