import numpy as np from .init import pipe TASK = "transcribe" BATCH_SIZE = 16 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, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"] print("transcribed_text : ", transcribed_text) return transcribed_text def predict(self): try: if self.mic is not None: chunk = self.mic.get_array_of_samples() audio = np.array(chunk) print("audio : ", 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"