Reaper200 commited on
Commit
7c10b80
·
verified ·
1 Parent(s): 28531a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import torchaudio
3
  from audiocraft.models import MusicGen
@@ -5,22 +6,27 @@ import requests
5
  from pydub import AudioSegment
6
  import os
7
 
 
 
 
8
  # Set Streamlit page configuration
9
  st.set_page_config(page_title="Suno-like AI Music Generator", layout="centered")
10
- st.title("Suno-like AI Music Generator")
 
 
 
 
11
 
12
- # Step 1: Load Pre-recorded AI Voice Sample
13
- st.subheader("Step 1: Pre-recorded AI Voice Sample")
14
- voice_url = "https://www2.cs.uic.edu/~i101/SoundFiles/StarWars60.wav" # Example URL for voice sample
15
  try:
16
  audio_data = requests.get(voice_url).content
17
- st.audio(audio_data, format="audio/wav")
18
  except Exception as e:
19
  st.error(f"Failed to load audio: {e}")
20
 
21
  # Step 2: User Input for Lyrics
22
- st.subheader("Step 2: Enter Lyrics for AI Voice")
23
- lyrics = st.text_area("Enter the lyrics you want to generate in the voice:", "Enter your lyrics here...")
24
 
25
  # Generate Instrumental with MusicGen
26
  st.subheader("Step 3: Generate Instrumental with MusicGen")
@@ -37,24 +43,23 @@ if st.button("Generate Music"):
37
  st.audio(output_path, format="audio/wav")
38
  st.success("Music generation complete!")
39
 
40
- # Step 4: Combine Lyrics with AI Voice and Instrumental (Simulated)
41
  st.subheader("Step 4: Simulated Combination of Lyrics, Voice, and Instrumental")
42
 
43
  if os.path.exists("musicgen_output.wav"):
44
- if st.button("Generate and Combine Voice + Music with Lyrics"):
45
  try:
46
- # Here we will use a voice sample and overlay the lyrics onto the instrumental
47
  beat = AudioSegment.from_wav("musicgen_output.wav")
48
 
49
- # For this example, we will use a male voice sample and overlay the lyrics
50
- # Simulating the AI voice generation for the lyrics
51
- voice = AudioSegment.from_wav("StarWars60.wav") # Replace with real AI voice generation logic
52
 
53
- # Adjust volumes and overlay (to avoid distortion)
54
  voice = voice - 4 # Reduce the voice volume
55
  beat = beat - 2 # Reduce the beat volume
56
 
57
- # Combine voice and instrumental
58
  combined = beat.overlay(voice, loop=False)
59
  combined_path = "combined_output.mp3"
60
  combined.export(combined_path, format="mp3")
 
1
+ import subprocess
2
  import streamlit as st
3
  import torchaudio
4
  from audiocraft.models import MusicGen
 
6
  from pydub import AudioSegment
7
  import os
8
 
9
+ # Run bash script to install dependencies
10
+ subprocess.run(['bash', './install_dependencies.sh'], check=True)
11
+
12
  # Set Streamlit page configuration
13
  st.set_page_config(page_title="Suno-like AI Music Generator", layout="centered")
14
+ st.title("AI Music Generator")
15
+
16
+ # Step 1: Load Pre-recorded Free AI Voice Sample from ResponsiveVoice
17
+ st.subheader("Step 1: voice ")
18
+ voice_url = "https://code.responsivevoice.org/getvoice.php?t=Hello%20world&tl=en&sv=g1&vn=&rate=0.5&pitch=0.5&volume=1" # Free male voice sample
19
 
20
+ # Attempt to download the voice sample
 
 
21
  try:
22
  audio_data = requests.get(voice_url).content
23
+ st.audio(audio_data, format="audio/mp3")
24
  except Exception as e:
25
  st.error(f"Failed to load audio: {e}")
26
 
27
  # Step 2: User Input for Lyrics
28
+ st.subheader("Step 2: Enter Lyrics")
29
+ lyrics = st.text_area("Enter the lyrics you want to generate:", "Enter your lyrics here...")
30
 
31
  # Generate Instrumental with MusicGen
32
  st.subheader("Step 3: Generate Instrumental with MusicGen")
 
43
  st.audio(output_path, format="audio/wav")
44
  st.success("Music generation complete!")
45
 
46
+ # Step 4: Combine Lyrics with Free AI Voice and Instrumental (Simulated)
47
  st.subheader("Step 4: Simulated Combination of Lyrics, Voice, and Instrumental")
48
 
49
  if os.path.exists("musicgen_output.wav"):
50
+ if lyrics:
51
  try:
52
+ # Load instrumental and voice
53
  beat = AudioSegment.from_wav("musicgen_output.wav")
54
 
55
+ # Use the voice sample from the provided URL (which is the free AI voice)
56
+ voice = AudioSegment.from_mp3("audio.mp3")
 
57
 
58
+ # Adjust volumes
59
  voice = voice - 4 # Reduce the voice volume
60
  beat = beat - 2 # Reduce the beat volume
61
 
62
+ # Combine the voice and instrumental
63
  combined = beat.overlay(voice, loop=False)
64
  combined_path = "combined_output.mp3"
65
  combined.export(combined_path, format="mp3")