vericudebuget commited on
Commit
b31f4bc
·
verified ·
1 Parent(s): 2e86752

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import gradio as gr
4
+ from audio_tuner import change_audio_tuning
5
+ import os
6
+
7
+ def tuning_interface(audio_input, initial_tuning, desired_tuning):
8
+ """
9
+ A wrapper function to connect the core logic to the Gradio interface.
10
+
11
+ Args:
12
+ audio_input (str): The temporary filepath of the uploaded audio provided by Gradio.
13
+ initial_tuning (float): The initial tuning frequency from the number input.
14
+ desired_tuning (float): The desired tuning frequency from the number input.
15
+
16
+ Returns:
17
+ (int, numpy.ndarray) or None: The processed audio data or None if an error occurs.
18
+ """
19
+ if audio_input is None:
20
+ raise gr.Error("Please upload an audio file first.")
21
+
22
+ try:
23
+ # The first argument from the gr.Audio input is the filepath
24
+ return change_audio_tuning(audio_input, initial_tuning, desired_tuning)
25
+ except ValueError as e:
26
+ # Display errors gracefully in the Gradio interface
27
+ raise gr.Error(str(e))
28
+ except Exception as e:
29
+ raise gr.Error(f"An unexpected error occurred: {e}")
30
+
31
+
32
+ # --- Define the Gradio Interface ---
33
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
34
+ gr.Markdown(
35
+ """
36
+ # Audio Tuning Speed Adjuster
37
+ Upload an audio file, set its original tuning frequency (e.g., A4 = 440Hz),
38
+ and then set your desired tuning frequency (e.g., A4 = 432Hz).
39
+ The app will slow down or speed up the audio to match the desired tuning without digital pitch correction.
40
+ """
41
+ )
42
+
43
+ with gr.Row():
44
+ with gr.Column():
45
+ audio_in = gr.Audio(type="filepath", label="Input Audio")
46
+
47
+ gr.Markdown("### Tuning Parameters")
48
+ initial_hz = gr.Number(label="Initial Tuning (Hz)", value=440)
49
+ desired_hz = gr.Number(label="Desired Tuning (Hz)", value=432)
50
+
51
+ submit_btn = gr.Button("Apply Tuning", variant="primary")
52
+
53
+ with gr.Column():
54
+ audio_out = gr.Audio(label="Tuned Audio", type="numpy")
55
+
56
+ submit_btn.click(
57
+ fn=tuning_interface,
58
+ inputs=[audio_in, initial_hz, desired_hz],
59
+ outputs=audio_out
60
+ )
61
+
62
+ gr.Examples(
63
+ examples=[
64
+ [None, 440, 432],
65
+ [None, 440, 528],
66
+ [None, 432, 444],
67
+ ],
68
+ inputs=[audio_in, initial_hz, desired_hz],
69
+ outputs=audio_out,
70
+ fn=tuning_interface,
71
+ cache_examples=False # Set to True if you have example audio files
72
+ )
73
+
74
+
75
+ # --- Run the App ---
76
+ if __name__ == "__main__":
77
+ demo.launch()