soiz1 commited on
Commit
29395b7
·
verified ·
1 Parent(s): 594a9cc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!pip install gradio pydub
2
+ #!apt install ffmpeg
3
+ import gradio as gr
4
+ from pydub import AudioSegment
5
+ import tempfile
6
+ import os
7
+
8
+ def process_audio(file,
9
+ left_source, # "left", "right", "mute"
10
+ right_source # "left", "right", "mute"
11
+ ):
12
+ # ステレオで読み込み
13
+ audio = AudioSegment.from_file(file)
14
+ left, right = audio.split_to_mono()
15
+
16
+ # ソース選択
17
+ def get_channel(source):
18
+ if source == "left":
19
+ return left
20
+ elif source == "right":
21
+ return right
22
+ else: # mute
23
+ return AudioSegment.silent(duration=len(audio))
24
+
25
+ new_left = get_channel(left_source)
26
+ new_right = get_channel(right_source)
27
+
28
+ # ステレオ再構築
29
+ combined = AudioSegment.from_mono_audiosegments(new_left, new_right)
30
+
31
+ # 一時ファイルに保存
32
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
33
+ combined.export(tmpfile.name, format="wav")
34
+ return tmpfile.name
35
+
36
+ # UIの設定
37
+ options = ["left", "right", "mute"]
38
+
39
+ demo = gr.Interface(
40
+ fn=process_audio,
41
+ inputs=[
42
+ gr.Audio(type="filepath", label="音声ファイル(ステレオ)"),
43
+ gr.Radio(choices=options, value="left", label="左チャンネルに流す音"),
44
+ gr.Radio(choices=options, value="right", label="右チャンネルに流す音")
45
+ ],
46
+ outputs=gr.Audio(label="出力音声(設定済みステレオ)"),
47
+ title="ステレオチャンネル編集ツール",
48
+ description="左・右チャンネルの音声ソースを個別に設定して、新しいステレオ音声を出力します。"
49
+ )
50
+
51
+ if __name__ == "__main__":
52
+ demo.launch(share=True, debug=True)