Ivan000 commited on
Commit
43f8e66
·
verified ·
1 Parent(s): 3e72e5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -10,7 +10,7 @@ import cv2
10
  import matplotlib.pyplot as plt
11
 
12
  # Function to generate frequency visualization frames from audio
13
- def generate_frequency_visualization(audio_path, fps, num_bars):
14
  try:
15
  # Load the audio file
16
  y, sr = librosa.load(audio_path, sr=None)
@@ -25,8 +25,8 @@ def generate_frequency_visualization(audio_path, fps, num_bars):
25
  S = np.abs(librosa.stft(y, n_fft=2048, hop_length=hop_length))
26
  S = S[:num_bars, :] # Limit the frequency bands to match the number of bars
27
 
28
- # Normalize frequency power
29
- S = S / np.max(S)
30
 
31
  # Create a directory to save the frames
32
  os.makedirs('frames', exist_ok=True)
@@ -94,11 +94,11 @@ def create_video_from_frames(frames_directory, audio_path, fps):
94
  return None
95
 
96
  # Gradio interface function
97
- def process_audio(audio):
98
  audio_path = audio
99
  fps = 60
100
  num_bars = 12
101
- frames_directory, duration = generate_frequency_visualization(audio_path, fps, num_bars)
102
  if frames_directory:
103
  video_path = create_video_from_frames(frames_directory, audio_path, fps)
104
  return video_path
@@ -108,13 +108,16 @@ def process_audio(audio):
108
  # Create the Gradio interface with explanations and recommendations
109
  iface = gr.Interface(
110
  fn=process_audio,
111
- inputs=gr.Audio(type="filepath", label="Upload Audio File"),
 
 
 
112
  outputs=gr.Video(label="Generated Video"),
113
  title="Audio Frequency Visualization",
114
  description="Upload an audio file to generate a video with frequency visualization. "
115
  "Supported file types: WAV, MP3, FLAC. "
116
  "Recommended file duration: 10 seconds to 5 minutes. "
117
- "The visualization will consist of 12 bars representing frequency ranges.",
118
  )
119
 
120
  # Launch the Gradio interface
 
10
  import matplotlib.pyplot as plt
11
 
12
  # Function to generate frequency visualization frames from audio
13
+ def generate_frequency_visualization(audio_path, fps, num_bars, sensitivity):
14
  try:
15
  # Load the audio file
16
  y, sr = librosa.load(audio_path, sr=None)
 
25
  S = np.abs(librosa.stft(y, n_fft=2048, hop_length=hop_length))
26
  S = S[:num_bars, :] # Limit the frequency bands to match the number of bars
27
 
28
+ # Normalize frequency power with sensitivity adjustment
29
+ S = (S / np.max(S)) * sensitivity
30
 
31
  # Create a directory to save the frames
32
  os.makedirs('frames', exist_ok=True)
 
94
  return None
95
 
96
  # Gradio interface function
97
+ def process_audio(audio, sensitivity):
98
  audio_path = audio
99
  fps = 60
100
  num_bars = 12
101
+ frames_directory, duration = generate_frequency_visualization(audio_path, fps, num_bars, sensitivity)
102
  if frames_directory:
103
  video_path = create_video_from_frames(frames_directory, audio_path, fps)
104
  return video_path
 
108
  # Create the Gradio interface with explanations and recommendations
109
  iface = gr.Interface(
110
  fn=process_audio,
111
+ inputs=[
112
+ gr.Audio(type="filepath", label="Upload Audio File"),
113
+ gr.Slider(minimum=0.1, maximum=5.0, step=0.1, value=1.0, label="Sensitivity")
114
+ ],
115
  outputs=gr.Video(label="Generated Video"),
116
  title="Audio Frequency Visualization",
117
  description="Upload an audio file to generate a video with frequency visualization. "
118
  "Supported file types: WAV, MP3, FLAC. "
119
  "Recommended file duration: 10 seconds to 5 minutes. "
120
+ "The visualization will consist of 12 bars representing frequency ranges. Adjust sensitivity to control bar movement.",
121
  )
122
 
123
  # Launch the Gradio interface