SPB Git

spb/doc-api

Public
5.3 KB · 107 lines markdown
1# Voice activity detection (VAD)23> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.45Voice activity detection (VAD) is a feature available in the Realtime API allowing to automatically detect when the user has started or stopped speaking.6It is enabled by default in [speech-to-speech](https://developers.openai.com/api/docs/guides/realtime-conversations) Realtime sessions, but is optional and can be turned off.7In [transcription](https://developers.openai.com/api/docs/guides/realtime-transcription) Realtime sessions, turn detection support depends on the transcription model. Models that support VAD default to `server_vad`, while `gpt-realtime-whisper` requires turn detection to be omitted or set to `null`.89## Overview1011When VAD is enabled, the audio is chunked automatically and the Realtime API sends events to indicate when the user has started or stopped speaking:1213- `input_audio_buffer.speech_started`: The start of a speech turn14- `input_audio_buffer.speech_stopped`: The end of a speech turn1516You can use these events to handle speech turns in your application. For example, you can use them to manage conversation state or process transcripts in chunks.1718You can configure VAD with the [`session.update`](https://developers.openai.com/api/reference/resources/realtime) client event by setting `session.audio.input.turn_detection`.1920There are two modes for VAD:2122- `server_vad`: Automatically chunks the audio based on periods of silence.23- `semantic_vad`: Chunks the audio when the model believes based on the words said by the user that they have completed their utterance.2425For sessions and models that support VAD, the default value is `server_vad`.2627Read below to learn more about the different modes.2829## Server VAD3031Server VAD is the default mode for speech-to-speech sessions, and for transcription sessions on models that support turn detection. It uses periods of silence to automatically chunk the audio.3233You can adjust the following properties to fine-tune the VAD settings:3435- `threshold`: Activation threshold (0 to 1). A higher threshold will require louder audio to activate the model, and thus might perform better in noisy environments.36- `prefix_padding_ms`: Amount of audio (in milliseconds) to include before the VAD detected speech.37- `silence_duration_ms`: Duration of silence (in milliseconds) to detect speech stop. With shorter values turns will be detected more quickly.3839Here is an example VAD configuration:4041```json42{43  "type": "session.update",44  "session": {45    "type": "realtime",46    "audio": {47      "input": {48        "turn_detection": {49          "type": "server_vad",50          "threshold": 0.5,51          "prefix_padding_ms": 300,52          "silence_duration_ms": 500,53          "create_response": true, // only in conversation mode54          "interrupt_response": true // only in conversation mode55        }56      }57    }58  }59}60```6162Use the same `session.audio.input.turn_detection` field in transcription sessions. For `gpt-realtime-whisper`, omit turn detection or set it to `null`.6364The `create_response` and `interrupt_response` fields are only used in speech-to-speech conversations. In transcription sessions, VAD only controls how audio is chunked.6566## Semantic VAD6768Semantic VAD is a new mode that uses a semantic classifier to detect when the user has finished speaking, based on the words they have uttered.69This classifier scores the input audio based on the probability that the user is done speaking. When the probability is low, the model will wait for a timeout, whereas when it is high, there is no need to wait.70For example, user audio that trails off with an "ummm..." would result in a longer timeout than a definitive statement.7172With this mode, the model is less likely to interrupt the user during a speech-to-speech conversation, or chunk a transcript before the user is done speaking.7374Semantic VAD can be activated by setting `session.audio.input.turn_detection.type` to `semantic_vad`.7576It can be configured like this:7778```json79{80  "type": "session.update",81  "session": {82    "type": "realtime",83    "audio": {84      "input": {85        "turn_detection": {86          "type": "semantic_vad",87          "eagerness": "low" | "medium" | "high" | "auto", // optional88          "create_response": true, // only in conversation mode89          "interrupt_response": true, // only in conversation mode90        }91      }92    }93  }94}95```9697The same `session.audio.input.turn_detection` field applies in transcription sessions. The `create_response` and `interrupt_response` fields are conversation-only.9899The optional `eagerness` property is a way to control how eager the model is to interrupt the user, tuning the maximum wait timeout. In transcription mode, even if the model doesn't reply, it affects how the audio is chunked.100101- `auto` is the default value, and is equivalent to `medium`.102- `low` will let the user take their time to speak.103- `high` will chunk the audio as soon as possible.104105If you want the model to respond more often in conversation mode, or to return transcription events faster in transcription mode, you can set `eagerness` to `high`.106107On the other hand, if you want to let the user speak uninterrupted in conversation mode, or if you would like larger transcript chunks in transcription mode, you can set `eagerness` to `low`.
Files · main
Menu

Theme