Text-to-Speech
ONNX
English
hexgrad adarksky commited on
Commit
e78b910
·
verified ·
1 Parent(s): 517bd02

Update kokoro.py (#43)

Browse files

- Update kokoro.py (fadcc6ac23dc3cfc0b8dd493767264691b0994e4)


Co-authored-by: Burning ray <[email protected]>

Files changed (1) hide show
  1. kokoro.py +16 -0
kokoro.py CHANGED
@@ -1,6 +1,7 @@
1
  import phonemizer
2
  import re
3
  import torch
 
4
 
5
  def split_num(num):
6
  num = num.group()
@@ -147,3 +148,18 @@ def generate(model, text, voicepack, lang='a', speed=1, ps=None):
147
  out = forward(model, tokens, ref_s, speed)
148
  ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
149
  return out, ps
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import phonemizer
2
  import re
3
  import torch
4
+ import numpy as np
5
 
6
  def split_num(num):
7
  num = num.group()
 
148
  out = forward(model, tokens, ref_s, speed)
149
  ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
150
  return out, ps
151
+
152
+ def generate_full(model, text, voicepack, lang='a', speed=1, ps=None):
153
+ ps = ps or phonemize(text, lang)
154
+ tokens = tokenize(ps)
155
+ if not tokens:
156
+ return None
157
+ outs = []
158
+ loop_count = len(tokens)//510 + (1 if len(tokens) % 510 != 0 else 0)
159
+ for i in range(loop_count):
160
+ ref_s = voicepack[len(tokens[i*510:(i+1)*510])]
161
+ out = forward(model, tokens[i*510:(i+1)*510], ref_s, speed)
162
+ outs.append(out)
163
+ outs = np.concatenate(outs)
164
+ ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
165
+ return outs, ps