oa.audio¶
OpenAI Audio tools
Functions
|
Convert text to speech using OpenAI's TTS API. |
|
Transcribe an audio or video file using OpenAI's Whisper API. |
|
Convert a transcription dict to SRT format string. |
|
Convert text to speech using OpenAI's TTS API. |
- oa.audio.text_to_speech(text, *, input, model='tts-1', voice='alloy', response_format='mp3', client=None, instructions=<openai.Omit object>, speed=<openai.Omit object>, stream_format=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Convert text to speech using OpenAI’s TTS API.
- Parameters:
text (
str) – Text to convert to speechmodel (
str) – TTS model to usevoice (
str) – Voice to use (alloy, echo, fable, onyx, nova, shimmer)response_format (
str) – Audio format (‘mp3’, ‘opus’, ‘aac’, ‘flac’, ‘wav’, ‘pcm’)client (
Union[OpenAI,str,dict,None]) – OpenAI client instance, API key string, config dict, or Nonekwargs – Additional parameters for the API
- Returns:
Audio content as bytes
Note
Actual API calls require a valid API key
- oa.audio.transcribe(audio, *, file, model='whisper-1', response_format='json', language=None, client=None, chunking_strategy=<openai.Omit object>, include=<openai.Omit object>, keywords=<openai.Omit object>, known_speaker_names=<openai.Omit object>, known_speaker_references=<openai.Omit object>, languages=<openai.Omit object>, prompt=<openai.Omit object>, stream=<openai.Omit object>, temperature=<openai.Omit object>, timestamp_granularities=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)[source]¶
Transcribe an audio or video file using OpenAI’s Whisper API.
- Parameters:
audio_file_path – Path to the audio/video file to transcribe
model (
str) – Transcription model to useresponse_format (
str) – Format for the response (‘json’, ‘text’, ‘srt’, ‘verbose_json’)language (
Optional[str]) – Optional ISO-639-1 language code (e.g., ‘en’, ‘fr’)client (
Union[OpenAI,str,dict,None]) – OpenAI client instance, API key string, config dict, or Nonekwargs – Additional parameters for the API
- Returns:
Dict with ‘text’, ‘segments’, ‘language’, and ‘raw_response’
Note
Actual API calls require a valid audio file and API key
- oa.audio.transcription_to_srt(transcription, *, segment_duration=None)[source]¶
Convert a transcription dict to SRT format string.
- Parameters:
- Return type:
- Returns:
SRT formatted string
>>> result = transcription_to_srt({'text': 'Hello world'}) >>> 'Hello world' in result True
- oa.audio.tts(text, *, input, model='tts-1', voice='alloy', response_format='mp3', client=None, instructions=<openai.Omit object>, speed=<openai.Omit object>, stream_format=<openai.Omit object>, extra_headers=None, extra_query=None, extra_body=None, timeout=NOT_GIVEN)¶
Convert text to speech using OpenAI’s TTS API.
- Parameters:
text (
str) – Text to convert to speechmodel (
str) – TTS model to usevoice (
str) – Voice to use (alloy, echo, fable, onyx, nova, shimmer)response_format (
str) – Audio format (‘mp3’, ‘opus’, ‘aac’, ‘flac’, ‘wav’, ‘pcm’)client (
Union[OpenAI,str,dict,None]) – OpenAI client instance, API key string, config dict, or Nonekwargs – Additional parameters for the API
- Returns:
Audio content as bytes
Note
Actual API calls require a valid API key