forked from ovbm/rejoha21-text-to-speech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (63 loc) · 2.05 KB
/
index.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
(function () {
// <code>
"use strict";
require('dotenv').config()
// pull in the required packages.
var sdk = require("microsoft-cognitiveservices-speech-sdk");
var readline = require("readline");
var fs = require("fs");
// replace with your own subscription key,
// service region (e.g., "westus"), and
// the name of the file you save the synthesized audio.
var subscriptionKey = process.env.SUBSCRIPTION_KEY;
var serviceRegion = "eastus"; // e.g., "westus"
var filename = "YourAudioFile.wav";
// we are done with the setup
// now create the audio-config pointing to our stream and
// the speech config specifying the language.
var audioConfig = sdk.AudioConfig.fromAudioFileOutput(filename);
var speechConfig = sdk.SpeechConfig.fromSubscription(
subscriptionKey,
serviceRegion
);
speechConfig.speechSynthesisLanguage = "de-DE";
speechConfig.speechSynthesisVoiceName = "de-DE-KatjaNeural";
// create the speech synthesizer.
var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function xmlToString(filePath) {
const xml = fs.readFileSync(filePath, "utf8");
return xml;
}
const ssml = xmlToString("ssml.xml");
rl.close();
// start the synthesizer and wait for a result.
synthesizer.speakSsmlAsync(
ssml,
function (result) {
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
console.log("synthesis finished.");
} else {
console.error(
"Speech synthesis canceled, " +
result.errorDetails +
"\nDid you update the subscription info?"
);
}
synthesizer.close();
synthesizer = undefined;
},
function (err) {
console.trace("err - " + err);
synthesizer.close();
synthesizer = undefined;
}
);
console.log("Now synthesizing to: " + filename);
// </code>
})();