Spaces:
Runtime error
Runtime error
get language code, instantiate allosaurus, recognize
Browse files
app.py
CHANGED
|
@@ -1,8 +1,38 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
uploaded_file = st.file_uploader("Choose a file")
|
| 5 |
if uploaded_file is not None:
|
| 6 |
audio_bytes = uploaded_file.getvalue()
|
| 7 |
# audio_bytes = audio_file.read()
|
| 8 |
-
st.audio(audio_bytes, format='audio/wav')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import langcodes
|
| 3 |
+
from allosaurus.app import read_recognizer
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_langcode_for_allosaurus(input_code):
|
| 10 |
+
langcode = "ipa" # the default allosaurus recognizer
|
| 11 |
+
try:
|
| 12 |
+
lang = langcodes.get(input_code)
|
| 13 |
+
langcode = lang.to_alpha3()
|
| 14 |
+
except langcodes.LanguageTagError as e:
|
| 15 |
+
pass
|
| 16 |
+
return langcode
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|
| 23 |
+
input_code = st.text_input("(optional) 2 or 3-letter ISO code for input language", max_chars=3)
|
| 24 |
+
langcode = get_langcode_for_allosaurus(input_code)
|
| 25 |
+
st.write(f"Instructing allosaurus to recognize using language {langcode}")
|
| 26 |
+
|
| 27 |
+
model = read_recognizer()
|
| 28 |
+
|
| 29 |
uploaded_file = st.file_uploader("Choose a file")
|
| 30 |
if uploaded_file is not None:
|
| 31 |
audio_bytes = uploaded_file.getvalue()
|
| 32 |
# audio_bytes = audio_file.read()
|
| 33 |
+
st.audio(audio_bytes, format='audio/wav')
|
| 34 |
+
|
| 35 |
+
result = model.recognize(audio_bytes, langcode)
|
| 36 |
+
st.write(result)
|
| 37 |
+
|
| 38 |
+
|