pratikshahp commited on
Commit
dcf6735
·
verified ·
1 Parent(s): ae714a7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
3
+ from audio_recorder_streamlit import audio_recorder
4
+ import numpy as np
5
+
6
+ def transcribe_audio(audio_bytes):
7
+
8
+ model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-small-mustc-en-fr-st")
9
+ processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-mustc-en-fr-st")
10
+
11
+ generated_ids = model.generate(input_ids=audio_bytes["input_features"], attention_mask=audio_bytes["attention_mask"])
12
+ translation = processor.batch_decode(generated_ids, skip_special_tokens=True)
13
+
14
+ return translation
15
+
16
+
17
+ st.title("Audio to Text Transcription..")
18
+ audio_bytes = audio_recorder(pause_threshold=3.0, sample_rate=16_000)
19
+ if audio_bytes:
20
+ st.audio(audio_bytes, format="audio/wav")
21
+
22
+ transcription = transcribe_audio(audio_bytes)
23
+ if transcription:
24
+ st.write("Transcription:")
25
+ st.write(transcription)
26
+ else:
27
+ st.write("Error: Failed to transcribe audio.")
28
+ else:
29
+ st.write("No audio recorded.")