Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
from pytube import YouTube
|
2 |
from google.cloud import speech_v1p1beta1 as speech
|
|
|
3 |
import io
|
4 |
import openai
|
5 |
import os
|
@@ -24,12 +25,18 @@ def get_yt_video_id(url):
|
|
24 |
else:
|
25 |
raise ValueError("μ ν¨ν μ νλΈ λ§ν¬κ° μλλλ€.")
|
26 |
|
27 |
-
# μ€λμ€ μΆμΆ ν¨μ
|
28 |
-
def
|
29 |
yt = YouTube(youtube_url)
|
30 |
stream = yt.streams.filter(only_audio=True).first()
|
31 |
audio_path = stream.download(filename="audio.mp4")
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Google Speech-to-Text APIλ₯Ό μ¬μ©νμ¬ μ€λμ€λ₯Ό ν
μ€νΈλ‘ λ³ν
|
35 |
def speech_to_text(audio_path):
|
@@ -40,8 +47,8 @@ def speech_to_text(audio_path):
|
|
40 |
|
41 |
audio = speech.RecognitionAudio(content=content)
|
42 |
config = speech.RecognitionConfig(
|
43 |
-
encoding=speech.RecognitionConfig.AudioEncoding.
|
44 |
-
sample_rate_hertz=16000,
|
45 |
language_code="ko-KR" # νκ΅μ΄ μΈμ
|
46 |
)
|
47 |
|
@@ -70,8 +77,8 @@ def textToSummary(text):
|
|
70 |
# μ 체 μμ½ νλ‘μΈμ€λ₯Ό μ²λ¦¬νλ ν¨μ
|
71 |
def summarize(url):
|
72 |
try:
|
73 |
-
# μ νλΈ μ€λμ€ λ€μ΄λ‘λ
|
74 |
-
audio_path =
|
75 |
# μμ±μ ν
μ€νΈλ‘ λ³ν
|
76 |
transcript = speech_to_text(audio_path)
|
77 |
# ν
μ€νΈ μμ½
|
|
|
1 |
from pytube import YouTube
|
2 |
from google.cloud import speech_v1p1beta1 as speech
|
3 |
+
from pydub import AudioSegment # μ€λμ€ λ³νμ μν λΌμ΄λΈλ¬λ¦¬
|
4 |
import io
|
5 |
import openai
|
6 |
import os
|
|
|
25 |
else:
|
26 |
raise ValueError("μ ν¨ν μ νλΈ λ§ν¬κ° μλλλ€.")
|
27 |
|
28 |
+
# μ€λμ€ μΆμΆ λ° λ³ν ν¨μ (WAV νμμΌλ‘ λ³ν)
|
29 |
+
def download_and_convert_audio(youtube_url):
|
30 |
yt = YouTube(youtube_url)
|
31 |
stream = yt.streams.filter(only_audio=True).first()
|
32 |
audio_path = stream.download(filename="audio.mp4")
|
33 |
+
|
34 |
+
# μ€λμ€ νμΌμ WAVλ‘ λ³ν (16000Hz μν λ μ΄νΈ)
|
35 |
+
audio = AudioSegment.from_file(audio_path)
|
36 |
+
wav_audio_path = "converted_audio.wav"
|
37 |
+
audio.set_frame_rate(16000).export(wav_audio_path, format="wav")
|
38 |
+
|
39 |
+
return wav_audio_path
|
40 |
|
41 |
# Google Speech-to-Text APIλ₯Ό μ¬μ©νμ¬ μ€λμ€λ₯Ό ν
μ€νΈλ‘ λ³ν
|
42 |
def speech_to_text(audio_path):
|
|
|
47 |
|
48 |
audio = speech.RecognitionAudio(content=content)
|
49 |
config = speech.RecognitionConfig(
|
50 |
+
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
|
51 |
+
sample_rate_hertz=16000, # 16000Hz μν λ μ΄νΈ
|
52 |
language_code="ko-KR" # νκ΅μ΄ μΈμ
|
53 |
)
|
54 |
|
|
|
77 |
# μ 체 μμ½ νλ‘μΈμ€λ₯Ό μ²λ¦¬νλ ν¨μ
|
78 |
def summarize(url):
|
79 |
try:
|
80 |
+
# μ νλΈ μ€λμ€ λ€μ΄λ‘λ λ° λ³ν
|
81 |
+
audio_path = download_and_convert_audio(url)
|
82 |
# μμ±μ ν
μ€νΈλ‘ λ³ν
|
83 |
transcript = speech_to_text(audio_path)
|
84 |
# ν
μ€νΈ μμ½
|