LLM/GPT활용

[1] 유튜브 영상 요약하기

EastHoon 2024. 5. 22. 11:03

동기

- CVPR 유튜브 영상을 챙겨 보다가 영상의 길이가 너무 길어, 이참에 OpenAI Whisper API를 이용한 동영상 요약을 진행해보고자 하였다.

CVPR #18546 - Denoising Diffusion Models: A Generative Learning Big Bang (youtube.com)

다음의 순서로 진행하고자 한다

1) Speech to text 

  - 유튜브 영상을 mp3로 전환

  -  mp3 파일을 txt로 변환하여 스크립트 저장

2) LLM을 이용한 텍스트 요약

 

Speech to text (Whisper 사용법)

-  Audio API는 transcriptions(필사), translations(번역) 기능을 제공한다. 

- mp3, mp4, mpeg, mpga, m4a, wav, webm 포맷을 지원하며, 현재는 25MB 파일 크기로 제한한다. 

 

설치

pip install -U openai-whisper

ffmpeg 도 설치를 해야 한다. 설치 방법은 아래 링크를 참고 합니다
- FFmpeg
- 윈도우에서 FFmpeg 설치하는 방법 (lainyzine.com)

 

 

Transcriptions

- Transcriptions API는 오디오 파일을 입력으로 받아 원하는 출력 형태로 필사해 준다.

- OpenAI API를 이용한 whisper 사용은 현재 large-v2 모델을 사용한다고 한다
  (모델 종류는 아래의 Available models and languages 표를 참고 한다)

  (아래 예시 코드는 whisper-1 이라 적혀 있고, large-v2 모델이다?)

from openai import OpenAI
client = OpenAI()

# Transcription
audio_file= open("/path/to/file/audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
  model="whisper-1", 
  file=audio_file,
  # response_format="text" json이 아닌 text로 결과를 내고자 한다면 주석 풉니다.
)
print(transcription.text)

# Translation
audio_file= open("/path/to/file/german.mp3", "rb")
translation = client.audio.translations.create(
  model="whisper-1", 
  file=audio_file
)
print(translation.text)
더보기

# Node

import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI()

async function main() {
	const transcription = await openai.audio.transcriptions.create({
   		file: fs.createReadStream(" /path/to/file/speech.mp3"),
        model: "whisper-1",
        response_format: "text",
	});
    console.log(transcription.text);
}

main()
# json 출력 결과
{ "text": "Imagine the wildest idea that you've ever had, and you're curious about how it might scale to something that's a 100, a 1,000 times bigger. .... }

 

 

Python Usage

- OpenAI() 클래스에서 호출해서 쓸 수도 있고, pip로 whisper를 따로 호출해서 사용할 수도 있나 보다.

- 4개의 모델은 영어 전용 버전이다.

import whisper

model = whisper.load_model("base")
result = model.transcribe("audio.mp3")
print(result["text"])

 

사용가능한 모델과 필요 메모리 요구 사항

 

 

 

 

시행 착오

- 비디오 사이즈 문제:  현재 비디오는 25MB 까지 지원을 하기 때문에 본인은 반디캠을 이용하여 비디오 사이즈를 분할하였다.

 

 

 

 

 

참고

- Introducing Whisper | OpenAI

- https://platform.openai.com/docs/guides/speech-to-text

- openai/whisper: Robust Speech Recognition via Large-Scale Weak Supervision (github.com)

 

GitHub - openai/whisper: Robust Speech Recognition via Large-Scale Weak Supervision

Robust Speech Recognition via Large-Scale Weak Supervision - openai/whisper

github.com

 

- Convert an mp4 video file into a text summary using python | by Darren Willenberg | MLthinkbox | Medium

 

Convert an mp4 video file into a text summary using python

In this post, we will use FFMPEG and the python speech_recognition module to convert an mp4 video file (e.g youtube) into a text summary.

medium.com

- YouTube Video Summarizer. Whisper. LangChain. | Python in Plain English

반응형