Spaces:
Running
Running
File size: 2,007 Bytes
72e17aa c3b86c9 72e17aa 3da71e7 72e17aa c3b86c9 3da71e7 c3b86c9 72e17aa 3da71e7 72e17aa c3b86c9 72e17aa c3b86c9 72e17aa | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | from kokoro import KModel, KPipeline
import os
import random
import numpy as np
import kokoro
import torch
voice_choices = {
'๐บ๐ธ ๐บ Heart โค๏ธ': 'af_heart',
'๐บ๐ธ ๐บ Bella ๐ฅ': 'af_bella',
'๐บ๐ธ ๐บ Nicole ๐ง': 'af_nicole',
'๐บ๐ธ ๐บ Aoede': 'af_aoede',
'๐บ๐ธ ๐บ Kore': 'af_kore',
'๐บ๐ธ ๐บ Sarah': 'af_sarah',
'๐บ๐ธ ๐บ Nova': 'af_nova',
'๐บ๐ธ ๐บ Sky': 'af_sky',
'๐บ๐ธ ๐บ Alloy': 'af_alloy',
'๐บ๐ธ ๐บ Jessica': 'af_jessica',
'๐บ๐ธ ๐บ River': 'af_river',
'๐บ๐ธ ๐น Michael': 'am_michael',
'๐บ๐ธ ๐น Fenrir': 'am_fenrir',
'๐บ๐ธ ๐น Puck': 'am_puck',
'๐บ๐ธ ๐น Echo': 'am_echo',
'๐บ๐ธ ๐น Eric': 'am_eric',
'๐บ๐ธ ๐น Liam': 'am_liam',
'๐บ๐ธ ๐น Onyx': 'am_onyx',
'๐บ๐ธ ๐น Santa': 'am_santa',
'๐บ๐ธ ๐น Adam': 'am_adam',
'๐ฌ๐ง ๐บ Emma': 'bf_emma',
'๐ฌ๐ง ๐บ Isabella': 'bf_isabella',
'๐ฌ๐ง ๐บ Alice': 'bf_alice',
'๐ฌ๐ง ๐บ Lily': 'bf_lily',
'๐ฌ๐ง ๐น George': 'bm_george',
'๐ฌ๐ง ๐น Fable': 'bm_fable',
'๐ฌ๐ง ๐น Lewis': 'bm_lewis',
'๐ฌ๐ง ๐น Daniel': 'bm_daniel',
}
model = KModel().to('cpu').eval()
pipeline = KPipeline(lang_code='a', model=False)
pipelines = {lang_code: KPipeline(lang_code=lang_code, model=False) for lang_code in 'ab'}
pipelines['a'].g2p.lexicon.golds['kokoro'] = 'kหOkษษนO'
pipelines['b'].g2p.lexicon.golds['kokoro'] = 'kหQkษษนQ'
def generate_tts(text, voice='af_heart', speed=1):
pipeline = pipelines[voice[0]]
pack = pipeline.load_voice(voice)
first = True
for _, ps, _ in pipeline(text, voice, speed):
ref_s = pack[len(ps)-1]
try:
audio = model(ps, ref_s, speed)
except:
print("lol there was an issue idk")
yield 24000, audio.numpy()
if first:
first = False
yield 24000, torch.zeros(1).numpy()
|