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