File size: 1,957 Bytes
1ffd672
f8d0565
 
ff1bae1
f8d0565
 
55c2b20
e4d471e
 
f37ce85
fa6f9dd
 
5caf6ad
bdc63d3
 
 
 
0f7a10e
f9db145
f8d0565
 
 
 
0c3b1db
f8d0565
 
 
0c3b1db
f8d0565
 
0c3b1db
f8d0565
 
 
 
1ffd672
 
f8d0565
0c3b1db
c198ba3
f8d0565
 
 
f9db145
 
f083023
 
 
 
f9db145
f083023
f9db145
f083023
 
 
 
 
 
 
 
 
 
f8d0565
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import streamlit as st
import langcodes
from allosaurus.app import read_recognizer
from pathlib import Path

  
def get_path_to_wav_format(uploaded_file):
  st.write(dir(uploaded_file))
  st.write(type(uploaded_file))
  st.write(uploaded_file)
  

  if ".wav" in uploaded_file.name:
    wav_bytes = uploaded_file.getvalue()
    actual_file_path = Path(uploaded_file.name)
    actual_file_path.write_bytes(wav_bytes)
    
    return Path(uploaded_file.name)
  # TODO: .mp3 conversion      


def get_langcode_for_allosaurus(input_code):
  langcode = "ipa" # the default allosaurus recognizer
  description = "the default universal setting, not specific to any language"
  try:
    lang = langcodes.get(input_code)
    langcode = lang.to_alpha3()
    description = lang.display_name()
  except langcodes.LanguageTagError as e:
    pass
  return langcode, description 
  
  
  


if __name__ == "__main__":
  input_code = st.text_input("(optional) 2 or 3-letter ISO code for input language", max_chars=3)
  langcode, description = get_langcode_for_allosaurus(input_code)
  st.write(f"Instructing Allosaurus to recognize using language {langcode}. That is, {description}")
  
  model = read_recognizer()
  
  uploaded_file = st.file_uploader("Choose a file", type=[
                                                          ".wav", 
#                                                          ".mp3", # TODO: convert .mp3 to .wav and save
                                                          ],
                                                    accept_multiple_files=True,
                                                          )
  
  for uploaded_file in uploaded_files:
    
    if uploaded_file is not None:
  
      
      
      st.audio(uploaded_file, format='audio/wav')
      
      wav_file = get_path_to_wav_format(uploaded_file)    
      st.write(wav_file)
      result = model.recognize(wav_file, langcode)
      st.write(result)