Zw07 commited on
Commit
782ddf5
·
verified ·
1 Parent(s): d7fb4cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -86,6 +86,15 @@ def create_default_value():
86
  def_val_str = "".join([str(i) for i in def_val_npy])
87
  st.session_state.def_value = def_val_str
88
 
 
 
 
 
 
 
 
 
 
89
  # Main web app
90
  def main():
91
  create_default_value()
@@ -114,24 +123,26 @@ def main():
114
  # f.write(audio_file.getbuffer())
115
  # st.audio(tmp_input_audio_file, format="mp3/wav")
116
 
 
 
117
  # Save file to local storage
118
  tmp_input_audio_file = os.path.join("/tmp/", audio_file.name)
119
- with open(tmp_input_audio_file, "wb") as f:
120
  f.write(audio_file.getbuffer())
121
 
122
- # Convert MP3 to WAV using pydub
123
- mp3_audio = AudioSegment.from_mp3(tmp_input_audio_file)
124
- wav_output_file = tmp_input_audio_file.replace(".mp3", ".wav")
125
- mp3_audio.export(wav_output_file, format="wav")
126
 
127
  # Load the WAV file using torchaudio
128
- wav, sample_rate = torchaudio.load(wav_output_file)
129
  st.markdown("Before unsquuezewav")
130
  st.markdown(wav)
131
  wav= wav.unsqueeze(0)
132
 
133
  # Play the audio file (WAV format)
134
- st.audio(wav_output_file, format="audio/wav")
135
 
136
  # wav, sample_rate = torchaudio.load(audio_file, format="mp3/wav")
137
  st.markdown("SR")
 
86
  def_val_str = "".join([str(i) for i in def_val_npy])
87
  st.session_state.def_value = def_val_str
88
 
89
+ def download_sample_audio():
90
+ url = "https://keithito.com/LJ-Speech-Dataset/LJ037-0171.wav"
91
+ with open("test.wav", "wb") as f:
92
+ resp = urllib.request.urlopen(url)
93
+ f.write(resp.read())
94
+
95
+ wav, sample_rate = torchaudio.load("test.wav")
96
+ return wav, sample_rate
97
+
98
  # Main web app
99
  def main():
100
  create_default_value()
 
123
  # f.write(audio_file.getbuffer())
124
  # st.audio(tmp_input_audio_file, format="mp3/wav")
125
 
126
+
127
+
128
  # Save file to local storage
129
  tmp_input_audio_file = os.path.join("/tmp/", audio_file.name)
130
+ with open("test.wav", "wb") as f:
131
  f.write(audio_file.getbuffer())
132
 
133
+ # # Convert MP3 to WAV using pydub
134
+ # mp3_audio = AudioSegment.from_mp3(tmp_input_audio_file)
135
+ # wav_output_file = tmp_input_audio_file.replace(".mp3", ".wav")
136
+ # mp3_audio.export(wav_output_file, format="wav")
137
 
138
  # Load the WAV file using torchaudio
139
+ wav, sample_rate = torchaudio.load("test.wav")
140
  st.markdown("Before unsquuezewav")
141
  st.markdown(wav)
142
  wav= wav.unsqueeze(0)
143
 
144
  # Play the audio file (WAV format)
145
+ st.audio(wav, format="audio/wav")
146
 
147
  # wav, sample_rate = torchaudio.load(audio_file, format="mp3/wav")
148
  st.markdown("SR")