import openai
import os
audio = 'output/output.mp3'
filename = 'input_test.mp3'
# audio.export('./output/'+filename, format="mp3")
# 음원 파일 열기
audio_file = open(audio, "rb")
# Whisper 모델을 활용해 텍스트 얻기
transcript = openai.Audio.transcribe("whisper-1", audio_file)
문제
링크: https://github.com/openai/openai-python/discussions/742
v1.0.0 Migration Guide · openai openai-python · Discussion #742
We have released a new major version of our SDK, and we recommend upgrading promptly. It's a total rewrite of the library, so many things have changed, but we've made upgrading easy with a code mig...
github.com
openai 패키지에서 Audio 모듈의 transcribe함수 사용할 때 나온 에러다.
위에 내가 사용한 코드가 올드 버전이어서 Migration Guide에 나온대로 수정해줘야한다.
올드 버전
import openai
openai.api_key = os.environ['OPENAI_API_KEY']
뉴 버전
# new
from openai import OpenAI
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY'], # this is also the default, it can be omitted
)
해결
1. api 키 넣어주기
import openai
from dotenv import load_dotenv
import os
load_dotenv()
GptApiKey = os.environ.get("API_Key")
client = openai.OpenAI(api_key=GptApiKey)
2. openai.Audio.transcribe를 client.audio.transcriptions.create로 변경해주기
#(변경 전)
transcript = openai.Audio.transcribe("whisper-1", audio_file)
#(변경 후)
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file)
참고 문서: https://platform.openai.com/docs/guides/speech-to-text/quickstart

교훈: 공식문서를 잘 읽어보자ㅎㅎ