CineAI commited on
Commit
294e7fb
1 Parent(s): 6d742e1

41727469634d6f6e6b65793a32302e30332e32343a31393532

Browse files
Files changed (1) hide show
  1. audio2text/a2t.py +6 -5
audio2text/a2t.py CHANGED
@@ -6,9 +6,10 @@ LIMIT = 90 # limit 90 seconds
6
 
7
  class A2T:
8
  def __init__(self, mic):
9
- self.mic = mic
 
10
 
11
- def __preproccess(self, audio, frame_rate):
12
  try:
13
  audio = audio / 32678.0
14
 
@@ -23,7 +24,7 @@ class A2T:
23
  audio = torch.tensor(audio)
24
  return audio
25
  except Exception as e:
26
- print("Error", e)
27
  return None
28
 
29
  def predict(self):
@@ -35,12 +36,12 @@ class A2T:
35
 
36
  try:
37
  forced_decoder_ids = processor.get_decoder_prompt_ids(language="english", task="transcribe")
38
- audio = self.__preproccess(audio=audio, frame_rate=frame_rate)
39
  inputs = processor(audio=audio, sampling_rate=16000, return_tensors="pt")
40
  predicted_ids = model.generate(**inputs, max_length=400, forced_decoder_ids=forced_decoder_ids)
41
  transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
42
  return transcription[0]
43
  except Exception as e:
44
- print("Error", e)
45
  return "Oops some kinda error"
46
 
 
6
 
7
  class A2T:
8
  def __init__(self, mic):
9
+ print(type(mic.export().read()))
10
+ self.mic = mic.export().read()
11
 
12
+ def __preprocces(self, audio, frame_rate):
13
  try:
14
  audio = audio / 32678.0
15
 
 
24
  audio = torch.tensor(audio)
25
  return audio
26
  except Exception as e:
27
+ print("Preprocces error", e)
28
  return None
29
 
30
  def predict(self):
 
36
 
37
  try:
38
  forced_decoder_ids = processor.get_decoder_prompt_ids(language="english", task="transcribe")
39
+ audio = self.__preprocces(audio=audio, frame_rate=frame_rate)
40
  inputs = processor(audio=audio, sampling_rate=16000, return_tensors="pt")
41
  predicted_ids = model.generate(**inputs, max_length=400, forced_decoder_ids=forced_decoder_ids)
42
  transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
43
  return transcription[0]
44
  except Exception as e:
45
+ print("Predict error", e)
46
  return "Oops some kinda error"
47