File size: 1,424 Bytes
738deb1 4218d4c 738deb1 4218d4c 738deb1 4218d4c 738deb1 4218d4c 738deb1 4218d4c 738deb1 4218d4c 738deb1 4218d4c 738deb1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import os
import gradio as gr
from pydub import AudioSegment
# ์ฌ๋ฌ PCM ํ์ผ์ ํฉ์ณ ํ๋์ MP3 ํ์ผ๋ก ๋ณํํ๋ ํจ์
def merge_pcm_to_mp3(pcm_files):
combined = AudioSegment.silent(duration=0) # ๋น ์ค๋์ค ์์
for pcm_file in pcm_files:
try:
# PCM ํ์ผ์ AudioSegment๋ก ๋ถ๋ฌ์ค๊ธฐ (์ํ๋ง ์๋์ ์ฑ๋์ ์ง์ ํด์ผ ํจ)
audio = AudioSegment.from_file(pcm_file.name, format="raw", frame_rate=16000, channels=1, sample_width=2)
# PCM ์ค๋์ค๋ฅผ ๊ฒฐํฉ
combined += audio
except Exception as e:
print(f"Error processing {pcm_file.name}: {str(e)}")
continue
# ๊ฒฐํฉ๋ ์ค๋์ค๋ฅผ MP3๋ก ์ ์ฅ
output_mp3_path = "combined_output.mp3"
combined.export(output_mp3_path, format="mp3")
return output_mp3_path
# Gradio UI ๊ตฌ์ฑ
def process_files(pcm_files):
output_mp3 = merge_pcm_to_mp3(pcm_files)
return output_mp3
# Gradio ์ธํฐํ์ด์ค ์ ์
with gr.Blocks() as demo:
with gr.Row():
file_input = gr.File(label="Upload PCM files", file_count="multiple", file_types=["pcm"])
file_output = gr.File(label="Download Combined MP3")
convert_button = gr.Button("Convert and Merge to MP3")
convert_button.click(fn=process_files, inputs=file_input, outputs=file_output)
# ์ฑ ์คํ
demo.launch()
|