LocalWhisperTranscriber
LocalWhisperTranscriber
LocalWhisperTranscriber로 로컬에 설치한 Whisper를 사용해 OpenAI의 Whisper 모델로 오디오 파일을 텍스트로 변환(전사)할 수 있어요. 인덱싱 파이프라인의 첫 번째 컴포넌트로 두면 돼요.
본문
개요
컴포넌트는 어떤 Whisper 모델을 사용할지도 알아야 해요. 컴포넌트 초기화 때 model 파라미터로 지정하면 돼요. 모든 전사는 실행 중인 머신에서 완료되며, 오디오가 제3자 제공자에게 전송되지는 않아요.
지정할 수 있는 다른 선택적 파라미터는 API 문서에서 확인하세요.
지원되는 오디오 형식과 언어는 Whisper API 문서와 공식 Whisper GitHub 저장소를 참고하세요.
LocalWhisperTranscriber는 whisper-haystack 통합 패키지의 일부예요. 이걸 다루려면 Whisper(torch도 함께 설치됨)와 함께 패키지를 설치해야 해요.
pip install whisper-haystack
pip install -U openai-whisper
사용법
단독 사용 예시예요.
import requests
from haystack_integrations.components.audio.whisper import LocalWhisperTranscriber
response = requests.get(
"https://ia903102.us.archive.org/19/items/100-Best--Speeches/EK_19690725_64kb.mp3",
)
with open("kennedy_speech.mp3", "wb") as file:
file.write(response.content)
transcriber = LocalWhisperTranscriber(model="tiny")
transcription = transcriber.run(sources=["./kennedy_speech.mp3"])
print(transcription["documents"][0].content)
파이프라인 안에서:
아래 파이프라인은 지정한 URL에서 오디오 파일을 가져와 전사해요. 먼저 LinkContentFetcher로 오디오 파일을 가져오고, LocalWhisperTranscriber로 오디오를 텍스트로 변환한 뒤, 마지막에 전사 텍스트를 출력해요.
from haystack_integrations.components.audio.whisper import LocalWhisperTranscriber
from haystack.components.fetchers import LinkContentFetcher
from haystack import Pipeline
pipe = Pipeline()
pipe.add_component("fetcher", LinkContentFetcher())
pipe.add_component("transcriber", LocalWhisperTranscriber(model="tiny"))
pipe.connect("fetcher", "transcriber")
result = pipe.run(
data={
"fetcher": {
"urls": [
"https://ia903102.us.archive.org/19/items/100-Best--Speeches/EK_19690725_64kb.mp3",
],
},
},
)
print(result["transcriber"]["documents"][0].content)