fix(voice): resume AudioContext to prevent suspended state blocking silence detection
This commit is contained in:
@@ -22,6 +22,9 @@ export function useSilenceDetector(options: SilenceDetectorOptions = {}) {
|
|||||||
function start(stream: MediaStream, onSilence: () => void): void {
|
function start(stream: MediaStream, onSilence: () => void): void {
|
||||||
stop()
|
stop()
|
||||||
audioCtx = new AudioContext()
|
audioCtx = new AudioContext()
|
||||||
|
// Some browsers start AudioContext in "suspended" state — resume so
|
||||||
|
// getByteFrequencyData returns real values instead of all zeros.
|
||||||
|
audioCtx.resume().catch(() => {})
|
||||||
const source = audioCtx.createMediaStreamSource(stream)
|
const source = audioCtx.createMediaStreamSource(stream)
|
||||||
const analyser = audioCtx.createAnalyser()
|
const analyser = audioCtx.createAnalyser()
|
||||||
analyser.fftSize = 256
|
analyser.fftSize = 256
|
||||||
|
|||||||
Reference in New Issue
Block a user