Skip to main content

Get Recent Audio

Retrieve the last 10 seconds of audio data from a user session.
This endpoint is restricted to the com.augmentos.shazam package only.

Endpoint

The code shows this endpoint is incorrectly defined as /api/audio/:userId at line 47, but it should be just /audio/:userId since the router is mounted at /api.

Parameters

Query Parameters

Response

Success (200):
  • Binary audio data stream
  • Content-Type: application/octet-stream
  • Format: PCM audio buffer (concatenated audio chunks)
Error (401):
Error (403):
Error (404):
Error (500):

Implementation

  • File: packages/cloud/src/routes/audio.routes.ts:47-91
  • Middleware: shazamAuthMiddleware - Validates package and API key
  • Service: Uses AudioManager.getRecentAudioBuffer()

Authorization

  • Only com.augmentos.shazam package is allowed
  • Requires valid API key for the package
  • Must specify target user ID in both URL and query parameters

Audio Processing

  • Returns buffered audio from userSession.audioManager.getRecentAudioBuffer()
  • Audio chunks are concatenated into single buffer
  • LC3 codec support is commented out but planned for future

Text-to-Speech

Convert text to speech using ElevenLabs API.

Endpoint

The code shows this endpoint is incorrectly defined as /api/tts at line 94, but it should be just /tts since the router is mounted at /api.

Query Parameters

Response

Success (200):
  • Audio stream
  • Content-Type: audio/mpeg
  • Streaming MP3 audio data
  • Connection: keep-alive
Error (400):
Error (500):

Voice Settings Example

Implementation

  • File: packages/cloud/src/routes/audio.routes.ts:94-223
  • Service: Proxies to ElevenLabs API
  • Streaming: Streams response directly to client using fetch API

Configuration

Requires environment variables:
  • ELEVENLABS_API_KEY: Your ElevenLabs API key
  • ELEVENLABS_DEFAULT_VOICE_ID: Default voice to use (optional if voice_id provided)

Example Request

ElevenLabs Integration

  • API endpoint: https://api.elevenlabs.io/v1/text-to-speech/{voice_id}/stream
  • Requires xi-api-key header for authentication
  • Supports streaming response for low latency

Error Codes

Notes

  • Audio endpoint is restricted to Shazam app for music recognition
  • TTS endpoint is publicly accessible but requires ElevenLabs configuration
  • Audio is buffered and retrieved from AudioManager
  • TTS responses are streamed for low latency
  • Both endpoints have incorrect route definitions that include /api prefix when they shouldn’t