Meteor 为什么每次流星呼叫时流星都会重新启动?
(这个问题被标记为可能是重复的,但它不是(据我所知),因为另一个问题是关于如何写入本地磁盘,这不是我的问题。我可以写入服务器磁盘没有问题,但这样做会导致Meteor重新启动。) 我的客户端代码中有一个Meteor.call(),它可以将Google Cloud文本保存为语音文件,并在服务器上创建指向客户端中声音文件的链接。然而,每次我调用Meteor时,Meteor服务器都会在完成任务后大约2秒钟重新启动。以下是客户端代码:Meteor 为什么每次流星呼叫时流星都会重新启动?,meteor,Meteor,(这个问题被标记为可能是重复的,但它不是(据我所知),因为另一个问题是关于如何写入本地磁盘,这不是我的问题。我可以写入服务器磁盘没有问题,但这样做会导致Meteor重新启动。) 我的客户端代码中有一个Meteor.call(),它可以将Google Cloud文本保存为语音文件,并在服务器上创建指向客户端中声音文件的链接。然而,每次我调用Meteor时,Meteor服务器都会在完成任务后大约2秒钟重新启动。以下是客户端代码: (client/main.js) Meteor.call('get.t
(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";
}
});
下面是服务器代码的样子(很抱歉长度和冗余——我不是一个真正的程序员):
重新启动不会强制重新加载页面(我只在meteor控制台上看到),但我认为它们会使速度减慢很多。我不知道tempSoundPath的值是什么,但它的行为就像是在将文件写入项目目录(服务器/…) Meteor将此视为源代码更改,并重建和重新启动服务器 这甚至在生产环境中也不起作用,因为您可能没有对文件系统的写访问权限
您最好将文件写入数据库,或者将其传递到S3存储桶。有像ostrio::files这样的meteor软件包可以帮助您实现这一点。我不知道您的tempSoundPath值是多少,但它的行为就像您正在将文件写入项目目录(服务器/…)中的某个位置) Meteor将此视为源代码更改,并重建和重新启动服务器 这甚至在生产环境中也不起作用,因为您可能没有对文件系统的写访问权限 您最好将文件写入数据库,或者将其传递到S3存储桶。有像ostrio::files这样的meteor软件包可以帮助您实现这一点。可能重复的
(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;
}
}