File size: 1,554 Bytes
1646f18
 
 
 
 
 
 
3c8b0eb
1646f18
3c8b0eb
1646f18
 
 
 
3c8b0eb
1646f18
 
 
 
 
 
 
 
 
 
 
 
 
3c8b0eb
1646f18
 
 
 
 
 
 
 
 
 
 
 
 
3c8b0eb
 
1646f18
 
3c8b0eb
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from parler_tts import ParlerTTSForConditionalGeneration
from transformers import AutoTokenizer
import soundfile as sf
import pygame
from dora import DoraStatus

model = ParlerTTSForConditionalGeneration.from_pretrained(
    "ylacombe/parler-tts-mini-jenny-30H"
).to("cuda:0")
tokenizer = AutoTokenizer.from_pretrained("ylacombe/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)