from parler_tts import ParlerTTSForConditionalGeneration from transformers import AutoTokenizer import soundfile as sf import pygame from dora import DoraStatus model = ParlerTTSForConditionalGeneration.from_pretrained( "/mnt/c/parler-tts-mini-jenny-30H" ).to("cuda:0") tokenizer = AutoTokenizer.from_pretrained("/mnt/c/parler-tts-mini-jenny-30H") pygame.mixer.init() input_ids = tokenizer( "Jenny delivers her words quite expressively, in a very confined sounding environment with clear audio quality.", return_tensors="pt", ).input_ids.to("cuda:0") class Operator: def on_event( self, dora_event, send_output, ): if dora_event["type"] == "INPUT": generation = model.generate( input_ids=input_ids, min_new_tokens=100, prompt_input_ids=tokenizer( dora_event["value"][0].as_py(), return_tensors="pt" ).input_ids.to("cuda:0"), ) print(dora_event["value"][0].as_py(), flush=True) sf.write( f"parler_tts_out.wav", generation.cpu().numpy().squeeze(), model.config.sampling_rate, ) pygame.mixer.music.load(f"parler_tts_out.wav") pygame.mixer.music.play() while pygame.mixer.get_busy(): pass return DoraStatus.CONTINUE # op = Operator() # import pyarrow as pa # op.on_event({"type": "INPUT", "value": pa.array(["Hello, how are you?"])}, None)