■ OpenAI 클래스의 audio 변수를 사용해 한국어 음성 파일을 영어 텍스트로 번역하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import os from openai import OpenAI os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>" openAI = OpenAI() audioFilePath = open("audio.mp3", "rb") translation = openAI.audio.translations.create( model = "whisper-1", file = audioFilePath ) print(translation) """ Translation( text = 'Whisper is a multi-tasking model that can learn a large set of audio data sets and perform multi-language voice recognition, voice translation, and language recognition.' ) """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
annotated-types==0.7.0 anyio==4.4.0 certifi==2024.6.2 distro==1.9.0 exceptiongroup==1.2.1 h11==0.14.0 httpcore==1.0.5 httpx==0.27.0 idna==3.7 openai==1.31.1 pydantic==2.7.3 pydantic_core==2.18.4 sniffio==1.3.1 tqdm==4.66.4 typing_extensions==4.12.1 |