Spaces:
Runtime error
Runtime error
KarthickAdopleAI
commited on
Commit
•
3647674
1
Parent(s):
a9ddfd3
Update app.py
Browse files
app.py
CHANGED
@@ -131,7 +131,28 @@ class VideoAnalytics:
|
|
131 |
except Exception as e:
|
132 |
logging.error(f"Error processing audio: {e}")
|
133 |
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
|
|
|
|
135 |
def transcribe_video(self, vid: str) -> str:
|
136 |
"""
|
137 |
Transcribe the audio of the video.
|
@@ -151,9 +172,11 @@ class VideoAnalytics:
|
|
151 |
|
152 |
# Replace 'input.mp3' and 'output.wav' with your file paths
|
153 |
audio_filename = self.mp3_to_wav("output_audio.mp3", 'output.wav')
|
154 |
-
|
|
|
|
|
155 |
# for detect lang
|
156 |
-
signal = self.language_id.load_audio(
|
157 |
prediction = self.language_id.classify_batch(signal)
|
158 |
lang = [prediction[3][0].split(":")][0][0]
|
159 |
text = self.get_large_audio_transcription_on_silence(audio_filename,lang)
|
|
|
131 |
except Exception as e:
|
132 |
logging.error(f"Error processing audio: {e}")
|
133 |
return ""
|
134 |
+
|
135 |
+
def split_audio(self,input_file):
|
136 |
+
# Load the audio file
|
137 |
+
audio = AudioSegment.from_file(input_file)
|
138 |
+
|
139 |
+
# Define segment length in milliseconds (5 minutes = 300,000 milliseconds)
|
140 |
+
segment_length = 60000
|
141 |
+
|
142 |
+
# Split the audio into segments
|
143 |
+
segments = []
|
144 |
+
for i, start_time in enumerate(range(0, len(audio), segment_length)):
|
145 |
+
# Calculate end time for current segment
|
146 |
+
end_time = start_time + segment_length if start_time + segment_length < len(audio) else len(audio)
|
147 |
+
|
148 |
+
# Extract segment
|
149 |
+
segment = audio[start_time:end_time]
|
150 |
+
|
151 |
+
# Append segment to list
|
152 |
+
segments.append(segment)
|
153 |
|
154 |
+
return segments
|
155 |
+
|
156 |
def transcribe_video(self, vid: str) -> str:
|
157 |
"""
|
158 |
Transcribe the audio of the video.
|
|
|
172 |
|
173 |
# Replace 'input.mp3' and 'output.wav' with your file paths
|
174 |
audio_filename = self.mp3_to_wav("output_audio.mp3", 'output.wav')
|
175 |
+
segments = self.split_audio(audio_filename)
|
176 |
+
splitted_audio_filename = segments[0].export("segment_for_1_min.wav",format="wav")
|
177 |
+
|
178 |
# for detect lang
|
179 |
+
signal = self.language_id.load_audio(splitted_audio_filename.name)
|
180 |
prediction = self.language_id.classify_batch(signal)
|
181 |
lang = [prediction[3][0].split(":")][0][0]
|
182 |
text = self.get_large_audio_transcription_on_silence(audio_filename,lang)
|