Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,39 @@ def main():
|
|
29 |
|
30 |
|
31 |
def get_audio_file_info(audio_file):
|
32 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def split_audio_into_clips(audio_file):
|
35 |
# Read the audio data from the file
|
|
|
29 |
|
30 |
|
31 |
def get_audio_file_info(audio_file):
|
32 |
+
# Read the audio data from the file
|
33 |
+
audio_data, sample_rate = sf.read(audio_file)
|
34 |
+
|
35 |
+
# Convert to mono if it's not mono
|
36 |
+
if len(audio_data.shape) > 1:
|
37 |
+
audio_data = np.mean(audio_data, axis=1)
|
38 |
+
|
39 |
+
# Get the audio file info
|
40 |
+
audio_info = sf.info(audio_file)
|
41 |
+
|
42 |
+
bit_depth = {'PCM_16': 16, 'FLOAT': 32}.get(audio_info.subtype, 0)
|
43 |
+
|
44 |
+
# Convert duration to minutes and seconds
|
45 |
+
minutes, seconds = divmod(audio_info.duration, 60)
|
46 |
+
|
47 |
+
# Convert bitrate to kbps
|
48 |
+
speed_in_kbps = audio_info.samplerate * bit_depth / 1000
|
49 |
+
|
50 |
+
# Create a table with the audio file info
|
51 |
+
info_table = f"""
|
52 |
+
|
53 |
+
| Information | Value |
|
54 |
+
| :---: | :---: |
|
55 |
+
| File Name | {os.path.basename(audio_file)} |
|
56 |
+
| Duration | {int(minutes)} minutes - {int(seconds)} seconds |
|
57 |
+
| Bitrate | {speed_in_kbps} kbp/s |
|
58 |
+
| Audio Channels | {audio_info.channels} |
|
59 |
+
| Samples per second | {audio_info.samplerate} Hz |
|
60 |
+
|
61 |
+
"""
|
62 |
+
|
63 |
+
# Return the info table
|
64 |
+
return info_table
|
65 |
|
66 |
def split_audio_into_clips(audio_file):
|
67 |
# Read the audio data from the file
|