(This question is marked as possibly being a duplicate, but it is not (as far as I can tell), because the other question is about HOW to write to local disk, and that's not my problem. I can write to the server disk no problem, but doing so causes Meteor to restart.)
I have a Meteor.call() in my client code that works as expected in saving Google Cloud Text-to-Speech files to the server and creating a link to the sound files in the client. However, every time I make the Meteor call, the Meteor server restarts itself after about 2 seconds after finishing its tasks. Here's the client code:
(client/main.js)
Meteor.call('get.tts.links', tempSoundPath, voice, currentForeign,
currentExample, function(error, result) {
if (error) {
alert('Error');
} else {
Session.set("links", result);
soundLink1 = 'tempsoundfiles/' + result[0] + ".mp3";
if (!result[1]) soundLink2 = "";
else soundLink2 = 'tempsoundfiles/' + result[1] + ".mp3";
}
});
Here's what the server code looks like (sorry for the length and redundancy--I'm not an actual programmer):
(server/main.js)
const textToSpeech = require('@google-cloud/text-to-speech');
....
....
'get.tts.links'(tempSoundPath, voice, currentForeign, currentExample) {
var path = "";
var soundFileId = "";
var text1 = currentForeign;
var text2 = currentExample;
var fileId = makepass();
const client = new textToSpeech.TextToSpeechClient();
const request = {
input: {
text: text1
},
voice: {
languageCode: "en-GB",
ssmlGender: 'MALE'
},
audioConfig: {
audioEncoding: 'MP3'
},
};
client.synthesizeSpeech(request, (err, response) => {
if (err) {
console.error('ERROR:', err);
return;
}
path = tempSoundPath + fileId + ".mp3";
console.log("path = " + path);
// Write the binary audio content to a local file
fs.writeFile(path, response.audioContent, 'binary', err => {
if (err) {
console.error('ERROR:', err);
return;
}
});
});
if (!text2 || text2 == "") {
var result = [];
result.push(fileId);
return result;
} else {
var fileId2 = makepass();
const request2 = {
input: {
text: text2
},
voice: {
languageCode: voice,
ssmlGender: 'FEMALE'
},
audioConfig: {
audioEncoding: 'MP3'
},
};
client.synthesizeSpeech(request2, (err, response) => {
if (err) {
console.error('ERROR:', err);
return;
}
var path2 = tempSoundPath + fileId2 + ".mp3";
// Write the binary audio content to a local file
fs.writeFile(path2, response.audioContent, 'binary', err => {
if (err) {
console.error('ERROR:', err);
return;
}
});
});
var result1 = [];
result1.push(fileId, fileId2);
return result1;
}
}
The restarts don't force a page reload (I only see them on the meteor console), but I think they are slowing things down quite a bit.