aix.audio¶
Audio operations interface for AIX.
Provides text-to-speech (TTS) and speech-to-text (transcription) capabilities.
Examples
Text to speech:
>>> from aix.audio import text_to_speech
>>> audio = text_to_speech("Hello, world!")
>>> audio.save("hello.mp3")
Transcription:
>>> from aix.audio import transcribe
>>> text = transcribe("speech.mp3")
>>> print(text)
'Hello, this is a test recording.'
Functions
|
Convert text to speech audio. |
|
Transcribe audio to text. |
|
Transcribe audio with detailed timestamps. |
|
Translate audio from any language to English. |
Classes
|
Wrapper for generated audio. |
|
Result of audio transcription. |
- class aix.audio.GeneratedAudio(data, model=None, text=None, voice=None, format='mp3')[source]¶
Bases:
objectWrapper for generated audio.
Provides convenient access to audio data and saving.
Examples
>>> audio = GeneratedAudio(data=b'...', model="tts-1") >>> audio.save("output.mp3") >>> data = audio.as_bytes()
- class aix.audio.TranscriptionResult(text, language=None, duration=None, segments=None, model=None)[source]¶
Bases:
objectResult of audio transcription.
Contains the transcribed text and optional metadata like segments and timestamps.
Examples
>>> result = TranscriptionResult(text="Hello world") >>> print(result.text) 'Hello world'
- aix.audio.text_to_speech(text, *, model=None, voice=None, speed=None, response_format='mp3', api_key=None, **kwargs)[source]¶
Convert text to speech audio.
- Parameters:
text (
str) – Text to convert to speechmodel (
str) – TTS model to use (e.g., ‘tts-1’, ‘tts-1-hd’)voice (
str) – Voice to use (‘alloy’, ‘echo’, ‘fable’, ‘onyx’, ‘nova’, ‘shimmer’)speed (
float) – Playback speed (0.25 to 4.0)response_format (
str) – Audio format (‘mp3’, ‘opus’, ‘aac’, ‘flac’)**kwargs – Additional provider-specific parameters
- Return type:
- Returns:
GeneratedAudio object
- Raises:
ImportError – If LiteLLM is not installed
Examples
>>> from aix.audio import text_to_speech >>> audio = text_to_speech("Hello, how are you?") >>> audio.save("greeting.mp3")
>>> # Different voice and speed >>> audio = text_to_speech( ... "This is a test.", ... voice="nova", ... speed=1.2 ... )
>>> # High quality >>> audio = text_to_speech( ... "Important announcement", ... model="tts-1-hd", ... voice="onyx" ... )
- aix.audio.transcribe(audio, *, engine=None, model=None, language=None, prompt=None, response_format='text', temperature=None, timestamp_granularities=None, api_key=None, **kwargs)[source]¶
Transcribe audio to text.
By default this routes through LiteLLM (OpenAI-style transcription). Pass
engine=to instead delegate to ascribedbackend — one façade over many ASR engines (local Whisper / faster-whisper / vosk, or cloud Deepgram / AssemblyAI / Groq / ElevenLabs / Google …) with speaker diarization and SRT/VTT output. The return type is unchanged either way, so existing callers are unaffected.- Parameters:
audio (
Union[str,Path,BinaryIO,bytes]) – Audio file path, file object, or bytes.engine (
str) – Optionalscribedbackend id (e.g."faster-whisper","deepgram"). When given, transcription is delegated to scribed (which resolves that engine’s own credentials); the LiteLLM path is bypassed. Requirespip install 'aix[scribed]'. Seescribed.list_backends().model (
str) – Transcription model (e.g.'whisper-1'); for a scribed engine, the engine-specific model (e.g. a Whisper size).language (
str) – Source language (ISO-639-1 code, e.g.'en','es').prompt (
str) – Optional text to guide the model’s style (LiteLLM path).response_format (
str) –'text'(default) →str;'srt'/'vtt'→ subtitlestr(scribed path); else →TranscriptionResult.temperature (
float) – Sampling temperature (LiteLLM path).timestamp_granularities (
list[str]) – Timestamp types (‘word’, ‘segment’) (LiteLLM path).**kwargs – Additional parameters (forwarded to LiteLLM, or to the scribed backend — e.g.
diarize=True).
- Return type:
Union[str,TranscriptionResult]- Returns:
strforresponse_formatin {text, srt, vtt}, else aTranscriptionResult.
Examples
>>> from aix.audio import transcribe >>> text = transcribe("recording.mp3") >>> # delegate to a scribed engine (local, free, diarized SRT): >>> srt = transcribe( ... "meeting.wav", engine="faster-whisper", response_format="srt" ... ) >>> dg = transcribe( ... "call.mp3", engine="deepgram", diarize=True, ... response_format="verbose_json", ... )
- aix.audio.transcribe_with_timestamps(audio, *, granularity='segment', model=None, **kwargs)[source]¶
Transcribe audio with detailed timestamps.
- Parameters:
- Return type:
- Returns:
TranscriptionResult with detailed segments
Examples
>>> from aix.audio import transcribe_with_timestamps >>> result = transcribe_with_timestamps("lecture.mp3") >>> for segment in result.segments: ... start = segment['start'] ... end = segment['end'] ... text = segment['text'] ... print(f"[{start:.2f}-{end:.2f}] {text}")
- aix.audio.translate_audio(audio, *, model=None, prompt=None, api_key=None, **kwargs)[source]¶
Translate audio from any language to English.
Note
Currently uses Whisper’s translation capability which translates to English.
- Parameters:
- Return type:
- Returns:
Translated text in English
Examples
>>> from aix.audio import translate_audio >>> english_text = translate_audio("spanish_audio.mp3") >>> print(english_text) 'This is the English translation.'