Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
from pydub import AudioSegment
|
4 |
import tempfile
|
@@ -6,8 +5,12 @@ import os
|
|
6 |
|
7 |
def process_audio(file,
|
8 |
left_source, # "left", "right", "mute"
|
9 |
-
right_source # "left", "right", "mute"
|
|
|
10 |
):
|
|
|
|
|
|
|
11 |
# ステレオで読み込み
|
12 |
audio = AudioSegment.from_file(file)
|
13 |
left, right = audio.split_to_mono()
|
@@ -27,13 +30,18 @@ def process_audio(file,
|
|
27 |
# ステレオ再構築
|
28 |
combined = AudioSegment.from_mono_audiosegments(new_left, new_right)
|
29 |
|
|
|
|
|
|
|
|
|
30 |
# 一時ファイルに保存
|
31 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=
|
32 |
-
combined.export(tmpfile.name, format=
|
33 |
return tmpfile.name
|
34 |
|
35 |
-
# UI
|
36 |
options = ["left", "right", "mute"]
|
|
|
37 |
|
38 |
theme = gr.themes.Base(
|
39 |
primary_hue="sky",
|
@@ -51,11 +59,9 @@ theme = gr.themes.Base(
|
|
51 |
shadow_drop_lg='*shadow_drop',
|
52 |
button_border_width='*block_border_width',
|
53 |
button_border_width_dark='*block_border_width',
|
54 |
-
# 以下を置き換え
|
55 |
button_primary_shadow='*shadow_drop',
|
56 |
button_primary_shadow_hover='*shadow_inset',
|
57 |
button_primary_shadow_active='*shadow_drop',
|
58 |
-
# 必要ならセカンダリも同様に
|
59 |
button_secondary_shadow='*shadow_drop',
|
60 |
button_secondary_shadow_hover='*shadow_inset',
|
61 |
button_secondary_shadow_active='*shadow_drop',
|
@@ -66,16 +72,18 @@ theme = gr.themes.Base(
|
|
66 |
button_primary_background_fill_dark='*primary_500',
|
67 |
button_primary_background_fill_hover_dark='*button_secondary_background_fill_hover',
|
68 |
)
|
|
|
69 |
demo = gr.Interface(
|
70 |
fn=process_audio,
|
71 |
inputs=[
|
72 |
gr.Audio(type="filepath", label="音声ファイル(ステレオ)"),
|
73 |
gr.Radio(choices=options, value="left", label="左チャンネルに流す音"),
|
74 |
-
gr.Radio(choices=options, value="right", label="右チャンネルに流す音")
|
|
|
75 |
],
|
76 |
outputs=gr.Audio(label="出力音声(設定済みステレオ)"),
|
77 |
title="ステレオチャンネル編集ツール",
|
78 |
-
description="
|
79 |
theme=theme
|
80 |
)
|
81 |
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from pydub import AudioSegment
|
3 |
import tempfile
|
|
|
5 |
|
6 |
def process_audio(file,
|
7 |
left_source, # "left", "right", "mute"
|
8 |
+
right_source, # "left", "right", "mute"
|
9 |
+
output_format # "元のまま", "wav", "mp3", ...
|
10 |
):
|
11 |
+
# 入力フォーマットを取得
|
12 |
+
original_format = os.path.splitext(file)[1][1:] # 例: ".wav" → "wav"
|
13 |
+
|
14 |
# ステレオで読み込み
|
15 |
audio = AudioSegment.from_file(file)
|
16 |
left, right = audio.split_to_mono()
|
|
|
30 |
# ステレオ再構築
|
31 |
combined = AudioSegment.from_mono_audiosegments(new_left, new_right)
|
32 |
|
33 |
+
# 出力フォーマットを決定
|
34 |
+
export_format = original_format if output_format == "元のまま" else output_format
|
35 |
+
suffix = f".{export_format}"
|
36 |
+
|
37 |
# 一時ファイルに保存
|
38 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmpfile:
|
39 |
+
combined.export(tmpfile.name, format=export_format)
|
40 |
return tmpfile.name
|
41 |
|
42 |
+
# UI設定
|
43 |
options = ["left", "right", "mute"]
|
44 |
+
format_options = ["元のまま", "wav", "mp3", "ogg", "flac"]
|
45 |
|
46 |
theme = gr.themes.Base(
|
47 |
primary_hue="sky",
|
|
|
59 |
shadow_drop_lg='*shadow_drop',
|
60 |
button_border_width='*block_border_width',
|
61 |
button_border_width_dark='*block_border_width',
|
|
|
62 |
button_primary_shadow='*shadow_drop',
|
63 |
button_primary_shadow_hover='*shadow_inset',
|
64 |
button_primary_shadow_active='*shadow_drop',
|
|
|
65 |
button_secondary_shadow='*shadow_drop',
|
66 |
button_secondary_shadow_hover='*shadow_inset',
|
67 |
button_secondary_shadow_active='*shadow_drop',
|
|
|
72 |
button_primary_background_fill_dark='*primary_500',
|
73 |
button_primary_background_fill_hover_dark='*button_secondary_background_fill_hover',
|
74 |
)
|
75 |
+
|
76 |
demo = gr.Interface(
|
77 |
fn=process_audio,
|
78 |
inputs=[
|
79 |
gr.Audio(type="filepath", label="音声ファイル(ステレオ)"),
|
80 |
gr.Radio(choices=options, value="left", label="左チャンネルに流す音"),
|
81 |
+
gr.Radio(choices=options, value="right", label="右チャンネルに流す音"),
|
82 |
+
gr.Dropdown(choices=format_options, value="元のまま", label="出力フォーマット")
|
83 |
],
|
84 |
outputs=gr.Audio(label="出力音声(設定済みステレオ)"),
|
85 |
title="ステレオチャンネル編集ツール",
|
86 |
+
description="左・右チャンネルの音声ソースを個別に設定し、出力フォーマットを選んで保存できます。",
|
87 |
theme=theme
|
88 |
)
|
89 |
|