Text-to-Speech
ONNX
English
adarksky commited on
Commit
fadcc6a
·
verified ·
1 Parent(s): 2f0893c

Update kokoro.py

Browse files

Adds support for longer texts by multiple pass through the model. Generation example using `'af_nicole'` - [here](https://aeryskyb.github.io/weird_corner/urgesurfing/)!

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