我记得曾经一度骂过用Python连接字符串.有人告诉我,在Python中创建一个字符串列表并在以后加入它们会更有效.我把这种做法带到了JavaScript和Ruby中,虽然我不确定它在后者中是否具有相同的好处.
任何人都可以告诉我,加入一个字符串数组并调用它是否更有效(资源和执行):加入它们或者根据需要在Ruby编程语言中连接一个字符串?
谢谢.
在向服务器端API发出"AJAX"请求时,我无法播放音频.
我有后端Node.js代码,它使用IBM的Watson Text-to-Speech服务来提供来自文本的音频:
var render = function(request, response) {
var options = {
text: request.params.text,
voice: 'VoiceEnUsMichael',
accept: 'audio/ogg; codecs=opus'
};
synthesizeAndRender(options, request, response);
};
var synthesizeAndRender = function(options, request, response) {
var synthesizedSpeech = textToSpeech.synthesize(options);
synthesizedSpeech.on('response', function(eventResponse) {
if(request.params.text.download) {
var contentDisposition = 'attachment; filename=transcript.ogg';
eventResponse.headers['content-disposition'] = contentDisposition;
}
});
synthesizedSpeech.pipe(response);
};
Run Code Online (Sandbox Code Playgroud)
我有客户端代码来处理:
var xhr = new XMLHttpRequest(),
audioContext = new AudioContext(),
source = audioContext.createBufferSource();
module.controllers.TextToSpeechController = {
fetch: function() {
xhr.onload = function() {
var playAudio = function(buffer) …Run Code Online (Sandbox Code Playgroud)