42 lines
2.1 KiB
Python
42 lines
2.1 KiB
Python
import os,time,json,pathlib,resource
|
|
ROOT=pathlib.Path(__file__).resolve().parent
|
|
os.environ['HF_HOME']=str(ROOT/'hf-cache')
|
|
os.environ['HF_HUB_DISABLE_IMPLICIT_TOKEN']='1'
|
|
os.environ['HF_HUB_DISABLE_TELEMETRY']='1'
|
|
os.environ['OMP_NUM_THREADS']='4'
|
|
os.environ['MKL_NUM_THREADS']='4'
|
|
start=time.perf_counter()
|
|
import torch,soundfile as sf
|
|
from pocket_tts import TTSModel,export_model_state
|
|
torch.set_num_threads(4)
|
|
model=TTSModel.load_model(language='german')
|
|
assert model.has_voice_cloning, 'Cloning weights were not loaded'
|
|
results={'model':'pocket-tts','voice':'existing Anna reference, 6 seconds','language':'german','device':'cpu','threads':4,'load_seconds':time.perf_counter()-start,'runs':[]}
|
|
t=time.perf_counter()
|
|
state=model.get_state_for_audio_prompt(ROOT/'reference.wav')
|
|
results['reference_encode_seconds']=time.perf_counter()-t
|
|
profile=ROOT/'Anna-pocket-german.safetensors'
|
|
export_model_state(state,str(profile))
|
|
profile.chmod(0o600)
|
|
t=time.perf_counter()
|
|
state=model.get_state_for_audio_prompt(profile)
|
|
results['saved_voice_load_seconds']=time.perf_counter()-t
|
|
text='Hallo Michael. Heute testen wir die Sprachausgabe auf deinem Rechner. Dein Zug nach Karlsruhe fährt um fünf Uhr einundzwanzig. Welche Stimme gefällt dir am besten?'
|
|
results['text']=text
|
|
for i in range(2):
|
|
t=time.perf_counter(); chunks=[];first=None
|
|
for chunk in model.generate_audio_stream(state,text):
|
|
if first is None:first=time.perf_counter()-t
|
|
chunks.append(chunk)
|
|
elapsed=time.perf_counter()-t
|
|
audio=torch.cat(chunks,dim=-1).detach().cpu().numpy().squeeze()
|
|
filename=f'pocket-anna-{i+1}.wav'
|
|
sf.write(ROOT/filename,audio,model.sample_rate)
|
|
duration=audio.shape[-1]/model.sample_rate
|
|
results['runs'].append({'seconds':elapsed,'audio_seconds':duration,'rtf':elapsed/duration,'first_chunk_seconds':first,'file':filename})
|
|
(ROOT/'anna-results.json').write_text(json.dumps(results,indent=2,ensure_ascii=False))
|
|
results['peak_rss_mib']=resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1024
|
|
results['success']=True
|
|
(ROOT/'anna-results.json').write_text(json.dumps(results,indent=2,ensure_ascii=False))
|
|
print(json.dumps(results,indent=2,ensure_ascii=False))
|