Views
No views yet
pip3 install git+https://github.com/mesolitica/DistilCodec1# wget https://huggingface.co/IDEA-Emdoor/DistilCodec-v1.0/resolve/main/model_config.json
2# wget https://huggingface.co/IDEA-Emdoor/DistilCodec-v1.0/resolve/main/g_00204000
3
4from distilcodec import DistilCodec, demo_for_generate_audio_codes
5from transformers import AutoTokenizer, AutoModelForCausalLM
6
7codec_model_config_path='model_config.json'
8codec_ckpt_path = 'g_00204000'
9
10codec = DistilCodec.from_pretrained(
11 config_path=codec_model_config_path,
12 model_path=codec_ckpt_path,
13 use_generator=True,
14 is_debug=False).eval()
15
16tokenizer = AutoTokenizer.from_pretrained('mesolitica/Malaysian-TTS-1.7B-v1')
17model = AutoModelForCausalLM.from_pretrained('mesolitica/Malaysian-TTS-1.7B-v1', torch_dtype = 'auto').cuda()1import soundfile as sf
2import re
3from tqdm import tqdm
4
5speakers = [
6 'husein',
7 'idayu',
8 'singaporean',
9 'DisfluencySpeech',
10 'singlish-speaker2050',
11 'singlish-speaker2202',
12 'haqkiem',
13]
14
15string = 'IC saya adalah, sembilan enam, kosong tiga, satu empat, one, one, one, one, A, B, C, D, D, yes, Husein is very cute, cute, cute.'
16
17for s in tqdm(speakers):
18
19 left = s +': ' + string
20 prompt = f'<|im_start|>{left}<|speech_start|>'
21
22 generate_kwargs = dict(
23 **tokenizer(prompt, return_tensors = 'pt', add_special_tokens = False).to('cuda'),
24 max_new_tokens=1024,
25 temperature=0.7,
26 do_sample=True,
27 repetition_penalty=1.1,
28 )
29 generation_output = model.generate(**generate_kwargs)
30 speech_token = tokenizer.decode(generation_output[0]).split('<|speech_start|>')[-1].replace('<|endoftext|>', '')
31 numbers = re.findall(r'speech_(\d+)', speech_token)
32 d = list(map(int, numbers))
33 y_gen = codec.decode_from_codes(
34 d,
35 minus_token_offset=False
36 )
37 sf.write(f'{s}.mp3', y_gen[0, 0].cpu().numpy(), 24000)singlish-speaker2202 and haqkiem had to generate 2 times to get better output that follow exact text input.123, you have to normalize it first to become one two three or one hundred twenty three or satu dua tiga or seratus dua puluh tiga. Feel free to use Malaya for normalization, Malaya support Malay and English normalization, read more at https://github.com/mesolitica/malaya/issues/247#issuecomment-3030313021A, A, A, A, B, B in our recordings is spoken as A A A A B B. We have no intention to improve it due to cost, but continue finetune using proper dataset should able to solve it.