adirsingh96 commited on
Commit
8318150
1 Parent(s): 3afb54d
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from transformers import Speech2TextProcessor, TFSpeech2TextForConditionalGeneration
3
+ from datasets import load_dataset
4
+ import soundfile as sf
5
+
6
+ model = TFSpeech2TextForConditionalGeneration.from_pretrained(
7
+ "facebook/s2t-small-librispeech-asr", from_pt=True
8
+ )
9
+ processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
10
+
11
+
12
+ def map_to_array(batch):
13
+ speech, _ = sf.read(batch["file"])
14
+ batch["speech"] = speech
15
+ return batch
16
+
17
+
18
+ ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
19
+ ds = ds.map(map_to_array)
20
+ ds.set_format(type="tf")
21
+
22
+ input_features = processor(
23
+ ds["speech"][0], sampling_rate=16000, return_tensors="tf"
24
+ ).input_features # Batch size 1
25
+ generated_ids = model.generate(input_features)
26
+
27
+ transcription = processor.batch_decode(generated_ids)