ASR OpenAI Whisper API
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    Setup

    %pip install openai -q
    %%bash 
    export OPENAI_API_KEY='sk-.....-M'
    # import os
    # openai.api_key = os.environ['OPENAI_API_KEY']

    Transcriptions

    import openai
    
    with open("Audio/marvin_minsky.mp3", "rb") as audio_file:
        transcript = openai.Audio.transcribe( 
            file = audio_file, 
            model = "whisper-1",
            response_format="text",
            language="en"
        )
    print(transcript)

    Alternate Output Formats

    with open("Audio/marvin_minsky.mp3", "rb") as audio_file:
        transcript2 = openai.Audio.transcribe( 
            file = audio_file, 
            model = "whisper-1",
            response_format="srt",
            language="en"
        )
    print(transcript2)
    with open("Audio/marvin_minsky.mp3", "rb") as audio_file:
        transcript3 = openai.Audio.transcribe( 
            file = audio_file, 
            model = "whisper-1",
            response_format="verbose_json",
            language="en"
        )
    print(transcript3)

    Spanish Transcriptions

    with open("Audio/easy_spanish_315.mp3", "rb") as audio_file:
        transcript_es = openai.Audio.transcribe( 
            file = audio_file, 
            model = "whisper-1",
            response_format="text",
            language="es"
        )
    print(transcript_es)

    Translation From Spanish to English

    with open("Audio/easy_spanish_315.mp3", "rb") as audio_file:
        translate = openai.Audio.translate( 
            file = audio_file, 
            model = "whisper-1",
            response_format="text",
            language="en"
        )
    print(translate)