You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

whisper_op.py 609 B

12345678910111213141516171819202122232425
  1. import pyarrow as pa
  2. import whisper
  3. from dora import DoraStatus
  4. model = whisper.load_model("base")
  5. class Operator:
  6. """
  7. Transforming Speech to Text using OpenAI Whisper model
  8. """
  9. def on_event(
  10. self,
  11. dora_event,
  12. send_output,
  13. ) -> DoraStatus:
  14. if dora_event["type"] == "INPUT":
  15. audio = dora_event["value"].to_numpy()
  16. audio = whisper.pad_or_trim(audio)
  17. result = model.transcribe(audio, language="en")
  18. send_output("text", pa.array([result["text"]]), dora_event["metadata"])
  19. return DoraStatus.CONTINUE