sema-elevenlabs

0.1.0

Synthesize speech and list voices with the ElevenLabs text-to-speech API

$ sema pkg install sema-elevenlabs
Readme Versions 1 Dependencies 0

sema-elevenlabs

Synthesize speech and list voices with the ElevenLabs text-to-speech API.

Install

sema pkg add sema-elevenlabs

Quick start

(import "sema-elevenlabs")

(define client (elevenlabs/client))            ; reads ELEVENLABS_API_KEY

;; Pick a voice, synthesize, and save the audio to disk.
(define voice (first (elevenlabs/voices client)))
(define audio (elevenlabs/text-to-speech client (get voice :voice-id)
                                          "Hello from Sema."))
(file/write-bytes "hello.mp3" audio)           ; => writes an MP3 file

elevenlabs/text-to-speech returns a raw audio bytevector (MP3 by default); pair it with file/write-bytes to save it, or hand it to any consumer of bytes.

API

Function Description
elevenlabs/client Build a client; api-key falls back to ELEVENLABS_API_KEY.
elevenlabs/voices List the voices available to the account.
elevenlabs/text-to-speech Synthesize speech for text; returns audio bytes.
elevenlabs/request Low-level JSON request escape hatch used by the wrappers.

elevenlabs/client

(elevenlabs/client)
(elevenlabs/client {:api-key "..."})

Builds a client map holding the base URL and API key. The key falls back to the ELEVENLABS_API_KEY environment variable; if neither is present it raises.

(define client (elevenlabs/client {:api-key "sk_..."}))

elevenlabs/voices

(elevenlabs/voices client)

Returns the list of voice maps under the account. Each voice has keys such as :voice-id, :name, and :category.

(map (fn (v) (get v :name)) (elevenlabs/voices client))
;; => ("Rachel" "Domi" "Bella" ...)

elevenlabs/text-to-speech

(elevenlabs/text-to-speech client voice-id text)
(elevenlabs/text-to-speech client voice-id text {:model-id "..." :voice-settings {...}})

Synthesizes text with the given voice and returns the raw audio as a bytevector. Options:

  • :model-id — model to use (default "eleven_multilingual_v2").
  • :voice-settings — a map of ElevenLabs voice settings (stability, similarity_boost, style, speed, ...).
(define audio (elevenlabs/text-to-speech client "21m00Tcm4TlvDq8ikWAM"
                                          "The quick brown fox."))
(file/write-bytes "fox.mp3" audio)

elevenlabs/request

(elevenlabs/request client method path body)

Low-level JSON request against the API base. Sends body as JSON, decodes the response to a keyword-keyed map, and raises on any non-2xx status with the method, path, status, and the API's error message.

(elevenlabs/request client "GET" "/voices" nil)

Authentication

Set your ElevenLabs API key in the environment:

export ELEVENLABS_API_KEY="sk_..."

Or pass it explicitly: (elevenlabs/client {:api-key "sk_..."}). The key is sent in the xi-api-key header and is never logged.

Testing

sema tests.sema

Offline tests cover client construction, input validation, and error mapping. Live tests hit api.elevenlabs.io and only run when ELEVENLABS_API_KEY is set.

License

MIT

VersionSizePublished
0.1.0 4 KB 2026-07-07 21:27:56
No dependencies