cahya commited on
Commit
9fbe6a6
β€’
1 Parent(s): 4553c4e

add gradio app

Browse files
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +45 -0
  3. packages.txt +2 -0
  4. requirements.txt +6 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Multilingual Asr
3
  emoji: 🌍
4
  colorFrom: red
5
  colorTo: red
1
  ---
2
+ title: Multilingual ASR
3
  emoji: 🌍
4
  colorFrom: red
5
  colorTo: red
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import soundfile as sf
2
+ import torch
3
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
4
+ import gradio as gr
5
+ import sox
6
+
7
+
8
+ def convert(inputfile, outfile):
9
+ sox_tfm = sox.Transformer()
10
+ sox_tfm.set_output_format(
11
+ file_type="wav", channels=1, encoding="signed-integer", rate=16000, bits=16
12
+ )
13
+ sox_tfm.build(inputfile, outfile)
14
+
15
+
16
+ model_name = "indonesian-nlp/wav2vec2-indonesian-javanese-sundanese"
17
+ processor = Wav2Vec2Processor.from_pretrained(model_name)
18
+ model = Wav2Vec2ForCTC.from_pretrained(model_name)
19
+
20
+ def parse_transcription(wav_file):
21
+ filename = wav_file.name.split('.')[0]
22
+ convert(wav_file.name, filename + "16k.wav")
23
+ speech, _ = sf.read(filename + "16k.wav")
24
+ input_values = processor(speech, sampling_rate=16_000, return_tensors="pt").input_values
25
+ logits = model(input_values).logits
26
+ predicted_ids = torch.argmax(logits, dim=-1)
27
+ transcription = processor.decode(predicted_ids[0], skip_special_tokens=True)
28
+ return transcription
29
+
30
+
31
+
32
+ output = gr.outputs.Textbox(label="Indonesian, Javanese or Sundanese")
33
+
34
+ input_ = gr.inputs.Audio(source="microphone", type="file")
35
+ #gr.Interface(parse_transcription, inputs = input_, outputs="text",
36
+ # analytics_enabled=False, show_tips=False, enable_queue=True).launch(inline=False);
37
+
38
+ gr.Interface(parse_transcription, inputs = input_, outputs=[output],
39
+ analytics_enabled=False,
40
+ show_tips=False,
41
+ theme='huggingface',
42
+ layout='vertical',
43
+ title="Multilingual Speech Recognition for Indonesian Languages",
44
+ description="Speech Recognition Live Demo for Indonesian, Javanese and Sundanese",
45
+ enable_queue=True).launch( inline=False)
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ libsndfile1
2
+ sox
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ gradio
2
+ soundfile
3
+ torch
4
+ transformers
5
+ sox
6
+ sentencepiece