import numpy as np import librosa import torch 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.get_array_of_samples() audio = np.array(chunk) print(audio) return self.__transcribe(inputs=audio, task=TASK) else: return "please provide audio" except Exception as e: print("Predict error", e) return "Oops some kinda error"