Skip to content

Commit

Permalink
feat support google custom voice
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Oct 30, 2023
1 parent eb2c390 commit 8c4d5a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/synth-audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ const synthGoogle = async(logger, {credentials, stats, language, voice, gender,
const client = new ttsGoogle.TextToSpeechClient(credentials);
const opts = {
voice: {
name: voice,
...( typeof voice === 'string' && {name: voice, ssmlGender: gender || 'SSML_VOICE_GENDER_UNSPECIFIED'}),

Check failure on line 260 in lib/synth-audio.js

View workflow job for this annotation

GitHub Actions / build

There should be no space after this paren
...( typeof voice === 'object' && {custom_voice: voice}),

Check failure on line 261 in lib/synth-audio.js

View workflow job for this annotation

GitHub Actions / build

There should be no space after this paren
languageCode: language,
ssmlGender: gender || 'SSML_VOICE_GENDER_UNSPECIFIED'
},
audioConfig: {audioEncoding: 'MP3'}
};
Expand Down
34 changes: 34 additions & 0 deletions test/synth.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,40 @@ test('Google speech synth tests', async(t) => {
client.quit();
});

test('Google speech Custom voice synth tests', async(t) => {
const fn = require('..');
const {synthAudio, client} = fn(opts, logger);

if (!process.env.GCP_CUSTOM_VOICE_FILE && !process.env.GCP_CUSTOM_VOICE_JSON_KEY || !process.env.GCP_CUSTOM_VOICE_MODEL) {
t.pass('skipping google speech synth tests since neither GCP_CUSTOM_VOICE_FILE nor GCP_CUSTOM_VOICE_JSON_KEY provided, GCP_CUSTOM_VOICE_MODEL is not provided');
return t.end();
}
try {
const str = process.env.GCP_CUSTOM_VOICE_JSON_KEY || fs.readFileSync(process.env.GCP_CUSTOM_VOICE_FILE);
const creds = JSON.parse(str);
let opts = await synthAudio(stats, {
vendor: 'google',
credentials: {
credentials: {
client_email: creds.client_email,
private_key: creds.private_key,
},
},
language: 'en-AU',
text: 'This is a test. This is only a test',
voice: {
reportedUsage:"REALTIME",
model: process.env.GCP_CUSTOM_VOICE_MODEL
}
});
t.ok(!opts.servedFromCache, `successfully synthesized google custom voice audio to ${opts.filePath}`);
} catch (err) {
console.error(err);
t.end(err);
}
client.quit();
});

test('AWS speech synth tests', async(t) => {
const fn = require('..');
const {synthAudio, client} = fn(opts, logger);
Expand Down

0 comments on commit 8c4d5a7

Please sign in to comment.