Update functions.py
Browse files- functions.py +34 -0
functions.py
CHANGED
@@ -101,6 +101,40 @@ def load_prompt():
|
|
101 |
|
102 |
###################### Functions #######################################################################################
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
@st.cache_resource
|
105 |
def load_models():
|
106 |
|
|
|
101 |
|
102 |
###################### Functions #######################################################################################
|
103 |
|
104 |
+
@st.cache_data
|
105 |
+
def get_yt_audio(url):
|
106 |
+
temp_audio_file = os.path.join('output', 'audio')
|
107 |
+
|
108 |
+
ydl_opts = {
|
109 |
+
'format': 'bestaudio/best',
|
110 |
+
'postprocessors': [{
|
111 |
+
'key': 'FFmpegExtractAudio',
|
112 |
+
'preferredcodec': 'mp3',
|
113 |
+
'preferredquality': '192',
|
114 |
+
}],
|
115 |
+
'outtmpl': temp_audio_file,
|
116 |
+
'quiet': True,
|
117 |
+
}
|
118 |
+
|
119 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
120 |
+
ydl.download([url])
|
121 |
+
|
122 |
+
with open(temp_audio_file+'.mp3', 'rb') as file:
|
123 |
+
audio_file = file.read()
|
124 |
+
|
125 |
+
return audio_file
|
126 |
+
|
127 |
+
if __name__ == "__main__":
|
128 |
+
video_url = url
|
129 |
+
temp_dir = r"C:\Users\nickm\OneDrive\Python_Code\Machine_Learning_Code\HuggingFace\ASR\temp"
|
130 |
+
temp_audio_file = download_audio(video_url, temp_dir)
|
131 |
+
with open(temp_audio_file+'.mp3', 'rb') as file:
|
132 |
+
audio_file = file.read()
|
133 |
+
|
134 |
+
# Use the audio_file variable here for further processing
|
135 |
+
print(len(audio_file))
|
136 |
+
|
137 |
+
|
138 |
@st.cache_resource
|
139 |
def load_models():
|
140 |
|