File size: 1,136 Bytes
bed01bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import io
from typing import Generator, Union

import numpy as np

from modules import generate_audio as generate
from modules.SentenceSplitter import SentenceSplitter
from modules.speaker import Speaker


def synthesize_stream(
    text: str,
    temperature: float = 0.3,
    top_P: float = 0.7,
    top_K: float = 20,
    spk: Union[int, Speaker] = -1,
    infer_seed: int = -1,
    use_decoder: bool = True,
    prompt1: str = "",
    prompt2: str = "",
    prefix: str = "",
    spliter_threshold: int = 100,
    end_of_sentence="",
) -> Generator[tuple[int, np.ndarray], None, None]:
    spliter = SentenceSplitter(spliter_threshold)
    sentences = spliter.parse(text)

    for sentence in sentences:
        wav_gen = generate.generate_audio_stream(
            text=sentence + end_of_sentence,
            temperature=temperature,
            top_P=top_P,
            top_K=top_K,
            spk=spk,
            infer_seed=infer_seed,
            use_decoder=use_decoder,
            prompt1=prompt1,
            prompt2=prompt2,
            prefix=prefix,
        )
        for sr, wav in wav_gen:
            yield sr, wav