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()