cdleong commited on
Commit
663ac44
1 Parent(s): 5d2138a

attempt at mp3 support with torchaudio

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -5,18 +5,22 @@ from pathlib import Path
5
 
6
 
7
  def get_path_to_wav_format(uploaded_file):
8
- st.write(dir(uploaded_file))
9
- st.write(type(uploaded_file))
10
- st.write(uploaded_file)
11
-
 
 
 
12
 
13
  if ".wav" in uploaded_file.name:
14
- wav_bytes = uploaded_file.getvalue()
15
- actual_file_path = Path(uploaded_file.name)
16
- actual_file_path.write_bytes(wav_bytes)
17
-
18
  return Path(uploaded_file.name)
19
- # TODO: .mp3 conversion
 
 
 
 
 
20
 
21
 
22
  def get_langcode_for_allosaurus(input_code):
 
5
 
6
 
7
  def get_path_to_wav_format(uploaded_file):
8
+ # st.write(dir(uploaded_file))
9
+ # st.write(type(uploaded_file))
10
+ # st.write(uploaded_file)
11
+ uploaded_bytes = uploaded_file.getvalue()
12
+ actual_file_path = Path(uploaded_file.name)
13
+ actual_file_path.write_bytes(uploaded_bytes)
14
+
15
 
16
  if ".wav" in uploaded_file.name:
 
 
 
 
17
  return Path(uploaded_file.name)
18
+ if ".mp3" in uploaded_file.name:
19
+ new_desired_path = actual_file_path.with_suffix(".wav")
20
+ waveform, sample_rate = torchaudio.load(actual_file_path)
21
+ st.info(waveform, sample_rate)
22
+ torchaudio.save(new_desired_path, waveform, sample_rate)
23
+ return new_desired_path
24
 
25
 
26
  def get_langcode_for_allosaurus(input_code):