File size: 977 Bytes
3edbfec e18fb9d a677076 54f1c88 2ba318d a677076 5b8ef5f a677076 e18fb9d 54f1c88 95bbb32 e18fb9d a677076 95bbb32 d2bbc44 95bbb32 6d73c34 95bbb32 a677076 294e7fb a677076 2ba318d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import numpy as np
from .init import pipe
TASK = "transcribe"
class A2T:
def __init__(self, mic):
self.mic = mic
def __transcribe(self, inputs, task: str = None):
if inputs is None:
print("Inputs None")
transcribed_text = pipe(inputs, generate_kwargs={"task": task}, return_timestamps=True)["text"]
print(transcribed_text)
return transcribed_text
def predict(self):
try:
if self.mic is not None:
chunk = self.mic
audio = np.array(chunk)
print(audio)
else:
return "please provide audio"
if isinstance(audio , np.ndarray):
return self.__transcribe(inputs=audio, task=TASK)
else:
return "Audio is not np array"
except Exception as e:
print("Predict error", e)
return "Oops some kinda error"
|