|
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" |
|
|