Spaces:
Runtime error
Runtime error
Update transcription_diarization.py
Browse files- transcription_diarization.py +14 -3
transcription_diarization.py
CHANGED
|
@@ -3,7 +3,7 @@ import time
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import urllib.parse
|
| 6 |
-
from moviepy.editor import VideoFileClip
|
| 7 |
import requests
|
| 8 |
from botocore.exceptions import ClientError
|
| 9 |
from config import aws_access_key_id, aws_secret_access_key
|
|
@@ -15,10 +15,21 @@ def convert_to_mono_audio(video_path, output_format='wav'):
|
|
| 15 |
try:
|
| 16 |
video = VideoFileClip(video_path)
|
| 17 |
audio = video.audio
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
video.close()
|
| 21 |
audio.close()
|
|
|
|
|
|
|
| 22 |
return output_path
|
| 23 |
except Exception as e:
|
| 24 |
print(f"Error during audio conversion: {str(e)}")
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import urllib.parse
|
| 6 |
+
from moviepy.editor import VideoFileClip, AudioFileClip
|
| 7 |
import requests
|
| 8 |
from botocore.exceptions import ClientError
|
| 9 |
from config import aws_access_key_id, aws_secret_access_key
|
|
|
|
| 15 |
try:
|
| 16 |
video = VideoFileClip(video_path)
|
| 17 |
audio = video.audio
|
| 18 |
+
|
| 19 |
+
# Convert stereo to mono by averaging the two channels
|
| 20 |
+
mono_audio = AudioFileClip(video_path).to_soundarray()
|
| 21 |
+
mono_audio = np.mean(mono_audio, axis=1)
|
| 22 |
+
|
| 23 |
+
# Create a new AudioFileClip with the mono audio
|
| 24 |
+
mono_clip = AudioFileClip(video_path).set_array_audio(mono_audio)
|
| 25 |
+
|
| 26 |
+
# Write the mono audio to file
|
| 27 |
+
mono_clip.write_audiofile(output_path, fps=audio.fps)
|
| 28 |
+
|
| 29 |
video.close()
|
| 30 |
audio.close()
|
| 31 |
+
mono_clip.close()
|
| 32 |
+
|
| 33 |
return output_path
|
| 34 |
except Exception as e:
|
| 35 |
print(f"Error during audio conversion: {str(e)}")
|