File size: 1,141 Bytes
b3361ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Streaming example: play each piece of audio as it is synthesised, show time to first audio.

pip install onnxruntime numpy huggingface_hub sounddevice
pip install https://huggingface.co/Suarify/kecil-tts-michael-v0.2/resolve/main/dist/kecil_tts_8m-0.3.0-py3-none-any.whl
"""
import time

import sounddevice as sd

from kecil_tts import SAMPLE_RATE, KecilTTS

TEXT = ('Selamat pagi, boleh saya bantu encik hari ini? Jumlah bayaran akaun anda ialah RM1,250.50. '
        'Terima kasih kerana menghubungi kami, sila tunggu sebentar.')

tts = KecilTTS.from_pretrained('Suarify/kecil-tts-michael-v0.2')       # downloads the 8.5 MB int8 model once

started = time.perf_counter()
first = None
pieces = tts.stream(TEXT)                                       # generator: one float32 array per piece
stream = sd.OutputStream(SAMPLE_RATE, channels=1, dtype='float32')
stream.start()
for chunk in pieces:
    if first is None:
        first = time.perf_counter() - started
        print(f'first audio after {first:.2f} s')
    stream.write(chunk)
print(f'total {time.perf_counter() - started:.2f} s, {len(tts.pieces(TEXT))} pieces')
stream.close()