docs / ctx.mic
api reference

ctx.mic

Their microphone, live, while your app is open — a voice over a beat, a voice memo, a tuner. Fave1 asks them first and never keeps the sound.

miccard mode · app mode

Calls

src/index.ts
const mic = await ctx.mic.open();          // speakers on: echo cancelling, noise and gain control
const rec = new MediaRecorder(mic.stream);  // or feed it to Web Audio
rec.start();
// …
rec.stop();
mic.stop();                                 // or ctx.mic.close() — every mic your app opened
optionWhat it doesdefault
echoThe browser removes what the speakers are playing from what the mic hears. Leave it on unless they wear earphonestrue
noiseNoise suppression. Good for speech, rough on singingtrue
gainAutomatic level. Turn it off when you set the level yourselftrue
fieldWhat it istype
streamOne audio track, no video — for MediaRecorder or createMediaStreamSourceMediaStream
trackThat audio trackMediaStreamTrack
echo · noise · gainWhat the browser actually applied — it may not honor everything you asked forboolean
latencyInput delay the device reports, in seconds — 0 when it doesn’t saynumber
stop()Turns this mic off. ctx.mic.active tells you if any is still onfunction

Sound only. Need mic in your manifest — it is a separate permission from camera, with its own switch. Without it, or with the switch off in Fave1 settings, open() rejects with denied.

What the person sees

The first open() each time your app opens shows Fave1’s line in your panel: Let <your app> use your microphone? When they tap Allow, their browser asks for that site. While a mic is on, a red dot sits in your panel’s header. Close your app, close Fave1, or call stop(), and the mic goes off.

Call open() from a button they pressed — “Record” — not at launch, and turn it off as soon as the take is done. Nothing is played back through the speakers unless you do it yourself.

Recording over your own sound

To record a voice over music you play with Web Audio, send both to one MediaStreamDestination and record that. Keep the mic out of the speakers, or it feeds back.

src/index.ts
const ac = new AudioContext();
const out = ac.createMediaStreamDestination();    // what gets recorded
const music = ac.createGain();                     // your beat goes in here
music.connect(ac.destination);                     // …to the speakers

const earphones = true;                            // ask them — off means the mic hears your speakers too
const mic = await ctx.mic.open({ echo: !earphones, noise: !earphones, gain: !earphones });
const voice = ac.createMediaStreamSource(mic.stream);
voice.connect(out);                                // voice → the recording only

// The person hears the beat late (output delay) and the mic hears them late (input delay),
// so the voice lands behind the beat. Delay the music by the same amount — in the recording only.
const late = ac.createDelay(1);
late.delayTime.value = (ac.outputLatency || 0) + (ac.baseLatency || 0) + mic.latency;
music.connect(late).connect(out);

const rec = new MediaRecorder(out.stream);

Wired earphones and built-in speakers are a few hundredths of a second. Bluetooth earphones can be a quarter of a second and browsers don’t always report it — give people a slider to nudge it.

When it doesn’t work

codeWhat happened · what to doretry
deniedNot declared, the switch is off, they tapped Not now, or their browser said no (reason not-now · browser). closed if open() lands after your app closedno
blockedThis site doesn’t let any microphone run on it (reason site). Offer the same thing in app mode, at <your-app>.fave1.appno
unavailableNo microphone (reason none) or the page isn’t https (insecure)no
busyAnother app is holding itlater

The rule

Only through ctx.mic. The sound stays on their page — save it only when they ask (a clip they keep with ctx.files, a download), say so in your listing if it ever leaves, and never identify people by their voice. An app that calls navigator.mediaDevices.getUserMedia itself, listens without a tap, or keeps the mic on after the feature is done gets sent back in review.