Commit
·
cdecc9d
1
Parent(s):
c42c510
fix
Browse files
.env
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
#change key to yours ,this is invalid
|
| 2 |
-
export SPEECH_KEY=
|
| 3 |
export SPEECH_REGION=eastus
|
| 4 |
|
|
|
|
| 1 |
#change key to yours ,this is invalid
|
| 2 |
+
export SPEECH_KEY=299085b1a64047eb96f97d6c24ad91a5
|
| 3 |
export SPEECH_REGION=eastus
|
| 4 |
|
audio.mp3
ADDED
|
Binary file (48 kB). View file
|
|
|
public/index.html
CHANGED
|
@@ -8,11 +8,7 @@
|
|
| 8 |
font-family: Arial, sans-serif;
|
| 9 |
margin: 0;
|
| 10 |
padding: 0;
|
| 11 |
-
|
| 12 |
-
justify-content: center;
|
| 13 |
-
align-items: center;
|
| 14 |
-
height: 100vh;
|
| 15 |
-
background-color: #f0f0f0;
|
| 16 |
}
|
| 17 |
|
| 18 |
h1 {
|
|
@@ -60,9 +56,12 @@
|
|
| 60 |
|
| 61 |
<script>
|
| 62 |
|
| 63 |
-
document.body.innerHTML += `<
|
| 64 |
-
api: <a href="${window.location.origin}/
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
function synthesizeSpeech(text, voice) {
|
|
|
|
| 8 |
font-family: Arial, sans-serif;
|
| 9 |
margin: 0;
|
| 10 |
padding: 0;
|
| 11 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
h1 {
|
|
|
|
| 56 |
|
| 57 |
<script>
|
| 58 |
|
| 59 |
+
document.body.innerHTML += `<div>
|
| 60 |
+
for azure tts api: <a href="${window.location.origin}/atts/${encodeURIComponent('replace you text in url')}">${window.location.origin}/tts/your_text</a>
|
| 61 |
+
</div>`
|
| 62 |
+
document.body.innerHTML += `<div>
|
| 63 |
+
api for short text less than 200 charaters : <a href="${window.location.origin}/tts/${encodeURIComponent('replace you text in url')}">${window.location.origin}/tts/your_text</a>
|
| 64 |
+
</div>`
|
| 65 |
|
| 66 |
|
| 67 |
function synthesizeSpeech(text, voice) {
|
server.js
CHANGED
|
@@ -52,11 +52,13 @@ app.get('/tts/:text', async (req, res) => {
|
|
| 52 |
} catch (error) {
|
| 53 |
console.error(error, 'try azure tts');
|
| 54 |
}
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
let audioFile = "audio.mp3";
|
| 61 |
let speechConfig = sdk.SpeechConfig.fromSubscription(process.env.SPEECH_KEY, process.env.SPEECH_REGION);
|
| 62 |
let audioConfig = sdk.AudioConfig.fromAudioFileOutput(audioFile);
|
|
@@ -64,61 +66,16 @@ app.get('/tts/:text', async (req, res) => {
|
|
| 64 |
speechConfig.speechSynthesisVoiceName = voice;
|
| 65 |
let synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
|
| 66 |
|
| 67 |
-
synthesizer.speakTextAsync(text,
|
| 68 |
-
function (result) {
|
| 69 |
-
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
|
| 70 |
-
console.log("synthesis finished.");
|
| 71 |
-
res.download(audioFile); // This will initiate file download
|
| 72 |
-
} else {
|
| 73 |
-
console.error("Speech synthesis canceled, " + result.errorDetails +
|
| 74 |
-
"\nDid you set the speech resource key and region values?");
|
| 75 |
-
}
|
| 76 |
-
synthesizer.close();
|
| 77 |
-
synthesizer = null;
|
| 78 |
-
},
|
| 79 |
-
function (err) {
|
| 80 |
-
console.trace("err - " + err);
|
| 81 |
-
synthesizer.close();
|
| 82 |
-
synthesizer = null;
|
| 83 |
-
});
|
| 84 |
-
console.log("Now synthesizing to: " + audioFile);
|
| 85 |
-
});
|
| 86 |
-
|
| 87 |
-
app.get('/atts/:text', (req, res) => {
|
| 88 |
-
const text = req?.params?.text || 'test';
|
| 89 |
|
| 90 |
-
|
| 91 |
-
"headers": {
|
| 92 |
-
"accept": "application/json",
|
| 93 |
-
"accept-language": "en-US,en;q=0.9",
|
| 94 |
-
"authorization": "",
|
| 95 |
-
"cache-control": "no-cache",
|
| 96 |
-
"content-type": "application/json",
|
| 97 |
-
"pragma": "no-cache",
|
| 98 |
-
"sec-ch-ua": "\"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"",
|
| 99 |
-
"sec-ch-ua-mobile": "?0",
|
| 100 |
-
"sec-ch-ua-platform": "\"Linux\"",
|
| 101 |
-
"sec-fetch-dest": "empty",
|
| 102 |
-
"sec-fetch-mode": "cors",
|
| 103 |
-
"sec-fetch-site": "same-site",
|
| 104 |
-
"Referer": "https://ttsopenai.com/",
|
| 105 |
-
"Referrer-Policy": "strict-origin-when-cross-origin"
|
| 106 |
-
},
|
| 107 |
-
"body": `{"model":"tts-1","voice":"alloy","speed":1,${text}}`,
|
| 108 |
-
"method": "POST"
|
| 109 |
-
});
|
| 110 |
-
|
| 111 |
-
const voice = req.query.voicename || "de-DE-SeraphinaMultilingualNeural";
|
| 112 |
|
| 113 |
-
speechConfig.speechSynthesisVoiceName = voice;
|
| 114 |
|
| 115 |
-
var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
|
| 116 |
|
| 117 |
synthesizer.speakTextAsync(text,
|
| 118 |
function (result) {
|
| 119 |
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
|
| 120 |
console.log("synthesis finished.");
|
| 121 |
-
res.
|
| 122 |
} else {
|
| 123 |
console.error("Speech synthesis canceled, " + result.errorDetails +
|
| 124 |
"\nDid you set the speech resource key and region values?");
|
|
|
|
| 52 |
} catch (error) {
|
| 53 |
console.error(error, 'try azure tts');
|
| 54 |
}
|
| 55 |
+
console.log('redirct to auretts');
|
| 56 |
+
res.redirect('/atts'+text);
|
| 57 |
+
});
|
| 58 |
|
| 59 |
+
app.get('/atts/:text', (req, res) => {
|
| 60 |
+
const text = req?.params?.text || 'test';
|
| 61 |
+
const voice = req?.query?.voicename || "de-DE-SeraphinaMultilingualNeural";
|
|
|
|
| 62 |
let audioFile = "audio.mp3";
|
| 63 |
let speechConfig = sdk.SpeechConfig.fromSubscription(process.env.SPEECH_KEY, process.env.SPEECH_REGION);
|
| 64 |
let audioConfig = sdk.AudioConfig.fromAudioFileOutput(audioFile);
|
|
|
|
| 66 |
speechConfig.speechSynthesisVoiceName = voice;
|
| 67 |
let synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
console.log('/attss',text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
|
|
|
| 72 |
|
|
|
|
| 73 |
|
| 74 |
synthesizer.speakTextAsync(text,
|
| 75 |
function (result) {
|
| 76 |
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
|
| 77 |
console.log("synthesis finished.");
|
| 78 |
+
res.sendFile(path.join(__dirname,audioFile)); // This will initiate file download
|
| 79 |
} else {
|
| 80 |
console.error("Speech synthesis canceled, " + result.errorDetails +
|
| 81 |
"\nDid you set the speech resource key and region values?");
|