Suarify commited on
Commit
6bdcdcf
·
verified ·
1 Parent(s): e9d73f8

Remove expressive-mode filter (belongs in Kucing TTS Space)

Browse files
Files changed (1) hide show
  1. kecil.js +4 -18
kecil.js CHANGED
@@ -10,13 +10,6 @@ import { normalize } from './g2p/ms_norm.js';
10
  import { chunk, loadG2P } from './g2p/ms_g2p.js';
11
 
12
  export const SAMPLE_RATE = 24000;
13
- export const EXP_STYLES = {
14
- sedih: [0.88, 0.80], gembira: [1.08, 1.10], marah: [0.95, 1.20],
15
- takut: [1.12, 0.90], terkejut: [1.20, 1.20], tenang: [0.96, 0.90],
16
- keliru: [1.04, 0.85], bingung: [1.04, 0.85], kecewa: [0.90, 0.72], penat: [0.92, 0.75]
17
- };
18
- export const EXP_EVENTS = ['ketawa', 'hela', 'nangis', 'tercungap'];
19
- export const EXP_REPO = 'Suarify/kucing-tts-seri-expression-0.1';
20
  const MAX_PHONEMES = 400; // trained on single sentences of at most 400 phonemes
21
  export const FIRST_MAX = 60; // streaming: first piece at most this many phonemes, sound starts early
22
  export const LATER_MAX = 160; // streaming: every later piece at most this many phonemes
@@ -52,7 +45,6 @@ export class Suaradee {
52
  try {
53
  const m = await StyleTextToSpeech2Model.from_pretrained(model, { dtype, device: d, ...(sessionOptions ? { session_options: sessionOptions } : {}) });
54
  const inst = new Suaradee(m, rules, d);
55
- inst.expressive = model === EXP_REPO;
56
  await inst.synth(inst.phonemize('Selamat pagi.')[0]); // warm-up: surfaces unsupported operators now, not on first use
57
  return inst;
58
  } catch (e) { lastErr = e; console.warn(`Suaradee: device ${d} failed`, e); }
@@ -72,16 +64,10 @@ export class Suaradee {
72
 
73
  ids(phonemes) { return this.g2p.tokens(phonemes); }
74
 
75
- async synth(phonemes, speed = 1.0, style = null) {
76
  const ids = this.ids(phonemes);
77
  const input_ids = new Tensor('int64', BigInt64Array.from(ids, (v) => BigInt(v)), [1, ids.length]);
78
- const feed = { input_ids, speed: new Tensor('float32', new Float32Array([speed]), [1]) };
79
- if (this.expressive) {
80
- const [f0, energy] = style && EXP_STYLES[style] ? EXP_STYLES[style] : [1, 1];
81
- feed.f0_scale = new Tensor('float32', new Float32Array([f0]), [1]);
82
- feed.energy = new Tensor('float32', new Float32Array([energy]), [1]);
83
- }
84
- const out = await this.model(feed);
85
  return out.waveform.data;
86
  }
87
 
@@ -113,13 +99,13 @@ export class Suaradee {
113
 
114
  // Yields one Float32Array per piece at SAMPLE_RATE; a pause-length gap between pieces. The consumer
115
  // gets the first piece before the rest is synthesised.
116
- async *stream(text, { speed = 1.0, pause = 0.12, firstMax = FIRST_MAX, style = null } = {}) {
117
  const gap = new Float32Array(Math.round(pause * SAMPLE_RATE));
118
  let emitted = false;
119
  for (const p of this.pieces(text, firstMax)) {
120
  if (!/\p{L}/u.test(p)) continue; // punctuation alone is not speech
121
  if (emitted) yield gap.slice();
122
- yield await this.synth(p, speed, style);
123
  emitted = true;
124
  }
125
  }
 
10
  import { chunk, loadG2P } from './g2p/ms_g2p.js';
11
 
12
  export const SAMPLE_RATE = 24000;
 
 
 
 
 
 
 
13
  const MAX_PHONEMES = 400; // trained on single sentences of at most 400 phonemes
14
  export const FIRST_MAX = 60; // streaming: first piece at most this many phonemes, sound starts early
15
  export const LATER_MAX = 160; // streaming: every later piece at most this many phonemes
 
45
  try {
46
  const m = await StyleTextToSpeech2Model.from_pretrained(model, { dtype, device: d, ...(sessionOptions ? { session_options: sessionOptions } : {}) });
47
  const inst = new Suaradee(m, rules, d);
 
48
  await inst.synth(inst.phonemize('Selamat pagi.')[0]); // warm-up: surfaces unsupported operators now, not on first use
49
  return inst;
50
  } catch (e) { lastErr = e; console.warn(`Suaradee: device ${d} failed`, e); }
 
64
 
65
  ids(phonemes) { return this.g2p.tokens(phonemes); }
66
 
67
+ async synth(phonemes, speed = 1.0) {
68
  const ids = this.ids(phonemes);
69
  const input_ids = new Tensor('int64', BigInt64Array.from(ids, (v) => BigInt(v)), [1, ids.length]);
70
+ const out = await this.model({ input_ids, speed: new Tensor('float32', new Float32Array([speed]), [1]) });
 
 
 
 
 
 
71
  return out.waveform.data;
72
  }
73
 
 
99
 
100
  // Yields one Float32Array per piece at SAMPLE_RATE; a pause-length gap between pieces. The consumer
101
  // gets the first piece before the rest is synthesised.
102
+ async *stream(text, { speed = 1.0, pause = 0.12, firstMax = FIRST_MAX } = {}) {
103
  const gap = new Float32Array(Math.round(pause * SAMPLE_RATE));
104
  let emitted = false;
105
  for (const p of this.pieces(text, firstMax)) {
106
  if (!/\p{L}/u.test(p)) continue; // punctuation alone is not speech
107
  if (emitted) yield gap.slice();
108
+ yield await this.synth(p, speed);
109
  emitted = true;
110
  }
111
  }