Answering live audio
Record the microphone in the browser and get answers about each 5 seconds of audio while you are still speaking. Clone this Next.js app to follow along, or fork it as a starting point.


By the end you will have the app running locally, and you will know how it captures and cuts the audio, how a server route sends each chunk and how the page shows the answers.
Prerequisites
- Node.js 24 or later, and git.
- An API key from the API keys page of the Hume Platform. See Authentication.
- A browser and a microphone.
Run the example
Clone the repository and install its dependencies. If you use nvm, run nvm use before npm install to select the version in .nvmrc.
Copy the example environment file.
Set your API key in .env.local. Next.js sends a variable to the browser only when its name starts with NEXT_PUBLIC_, so the key stays on the server. A HUME_API_KEY exported in your shell takes precedence over the file.
Start the development server and open http://localhost:3000.
Press Record and speak, and allow microphone access when the browser asks. Answers appear under the waveform every 5 seconds. Press Stop, then click a chunk to see its answers in full, or press Play to replay the recording. Between recordings, edit the questions and the optional Context in the left panel.
How it works
Adapt it to your app
- Change the questions. The default questions and context are
DEFAULT_QUESTIONSandDEFAULT_CONTEXTinlib/questions.ts. To try a question before you change the code, add it in the app’s question panel. The app keeps your edits to the questions and context for the browser tab, so open a new tab to see changed defaults. See Writing questions. - Choose a chunk length.
CHUNK_MSinlib/recording.tssets it. The default of 5 seconds is the shortest the API accepts and answers soonest. Longer chunks send fewer requests and give each answer more audio to judge. Blocks are never split, so a chunk can run up to 125 ms pastCHUNK_MS. KeepCHUNK_MSat least that far below 5 minutes, the longest audio the API accepts. At 5 seconds a recording sends 12 requests a minute, and every API key in your organization shares a limit of 60 requests a minute. See Limits. - Act on the answers. Each chunk’s answers arrive in
sendChunkinhooks/use-recorder.ts, as theresponseof a chunk whose status isanswered. Compare an answer with a threshold there to act on it, such as flagging a chunk where the speaker sounds angry. See Interpreting answers. - Use a different audio source.
openMicrophonehandsuseRecorder125 ms blocks of mono samples with their sample rate, callsonEndedwhen the stream ends and returns the sample rate with aclosefunction. Any source that does the same, such as the audio of a call, can replace it, and the chunking and requests stay as they are. - Before you deploy. The route has no sign-in, so anyone who can reach it can spend your API key.
npm run devaccepts connections from other devices on your network, andnpm run dev -- -H localhostlimits it to your own machine. Add authentication to the route before you deploy it.