nemo_voice_agent.pipecat.services.nemo.audio_logger
nemo_voice_agent.pipecat.services.nemo.audio_logger
Module Contents
Classes
API
Utility class for logging audio data and transcriptions during voice agent interactions.
This logger saves:
- Audio files in WAV format
- Transcriptions with metadata in JSON format
- Session information and metadata
12/19/2025 Note: Stereo conversation recording is implemented,
but -0.8 seconds offset needs to be applied to make the session sound synced.
Parameters:
Base directory for storing logs (default: ”./audio_logs”)
Optional custom session ID. If None, auto-generated from timestamp
Whether logging is enabled (default: True)
Append audio to the stereo conversation buffer at the correct time position.
Parameters:
Audio data as bytes or numpy array
“left” for agent, “right” for user
Start time in seconds from session start
Sample rate of the input audio
Get the next counter value for a speaker in a thread-safe manner.
Resample audio data to a target sample rate using librosa.
Parameters:
Audio data as bytes (int16) or numpy array
Original sample rate
Target sample rate
Returns: np.ndarray
Resampled audio as numpy array (float32)
Save audio data to a WAV file.
Parameters:
Audio data as bytes or numpy array
Path to save the WAV file
Audio sample rate in Hz
Number of audio channels (default: 1)
Save metadata to a JSON file.
Save the session metadata to disk.
Append audio data to the continuous user audio buffer for stereo conversation.
This method should be called for EVERY audio frame received from the user, regardless of VAD state, to record the complete conversation audio.
Parameters:
Raw audio data as bytes
Clear the user audio buffer if the user stopped speaking detected by VAD.
Finalize the session and save final metadata.
Get the time from the start of the session to the given datetime string.
Increment the turn index if the speaker has changed.
Parameters:
“user” or “agent”. If provided, only increments if this is different from the current speaker. If None, always increments.
Returns: int
The current turn index after any increment.
Log agent audio and text (from TTS).
Parameters:
Generated audio data as bytes or numpy array
Input text that was synthesized
Audio sample rate in Hz (default: 22050)
Number of audio channels (default: 1)
Additional metadata to include
Time when TTS generation started (seconds from session start). Used to calculate actual start_time for first segment of a turn.
Returns: Optional[dict]
Dictionary with logged file paths, or None if logging is disabled
Save the stereo conversation buffer to a WAV file. Left channel = Agent, Right channel = User.
User audio comes from continuous_user_audio_buffer (not affected by VAD).
Save the user audio to the disk.
Parameters:
Whether this audio is a backchannel utterance (default: False)
Set the cutoff time for the most recent agent audio entry.
This method should be called when TTS is interrupted by user speech. The cutoff_time represents when the agent audio was actually cut off, which may be earlier than the natural end_time.
Parameters:
The cutoff time in seconds from session start. If None, uses current time from session start.
Set the start time for the current agent turn.
This should be called when BotStartedSpeakingFrame is received, which indicates the audio is actually starting to play (not just generated). This provides more accurate timing than capturing time during TTS generation.
Stage the complete turn audio and accumulated transcriptions.
This method is called when a final transcription is received. It joins all accumulated audio and transcription chunks and stages them together.
Parameters:
Timestamp when the audio was received
Whether this is the first frame of a turn (default: False)
Additional metadata to include (e.g., model, backend info)
Stage user audio metadata and transcription (from STT).
This data will be saved when the turn is complete by save_user_audio method.
Audio data is retrieved from continuous_user_audio_buffer based on timestamps.
Parameters:
Timestamp when the audio was received
Transcribed text
Audio sample rate in Hz (default: 16000)
Number of audio channels (default: 1)
Whether this is the first frame of a turn (default: False)
Whether this is a backchannel utterance (default: False)
Additional metadata to include
Returns: Optional[dict]
Dictionary with logged file paths, or None if logging is disabled
Bases: BaseObserver
Observer that triggers audio logging when TranscriptionFrame is pushed.
Handle frame push events and save user audio on TranscriptionFrame.