简体   繁体   English

如何将 code.gs 中的变量添加到 Audio src?

[英]How to Add variable from code.gs to Audio src?

Need help to fix this code please需要帮助来修复此代码

I want to Add the value of my Variable to the src of my audio, so that the text to speech will read the value from my spreadsheet as text.我想将变量的值添加到音频的 src 中,以便文本到语音将从我的电子表格中读取值作为文本。

  function checkCalls() {
  
  google.script.run.withSuccessHandler(function (columnH) {
  var div = document.getElementById('call2');
  var newvar = getColumnH();
  div.src = "https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl=en&q=" + newvar + "NEXT+CUSTOMER+PLEASE"
    for (var i = 0; i < columnH.length; i++) {

      // if there's a difference and it's a call, notify the user
      if (lastTime[i] !== columnH[i] && columnH[i] === "Call") {
        notify();
      }
    }

    // store results for next time
    lastTime = columnH;

    console.log(lastTime);

    // poll again in x miliseconds
    var x = 1000; // 1 second
    window.setTimeout(checkCalls, x);
  }).getColumnH();
}

newvar is from my code.gs newvar 来自我的 code.gs

function getColumnH() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DASHBOARD");
// get the values in column H and turn the rows into a single values
var newvar = getColumnA();
console.log(newvar);
return sheet.getRange(1, 8, sheet.getLastRow(), 1).getValues().map(function (row) { return row[0]; 
});
}

function getColumnA(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("CONTROLS");
var r =  s.getRange("A1")
var lastvalue = r.getValues();
return lastvalue;
}

Div is not an audio element you should use Audio Element instead Div 不是音频元素,您应该改用 Audio Element

By seeing your code var div = document.getElementById('call2');通过查看您的代码var div = document.getElementById('call2');

The correct use of HTML5 Audio generated should be:正确使用 HTML5 生成的音频应该是:

<audio controls>
  <source id="call2" src="added programatically" type="audio/mpeg">
</audio>

Or或者

<audio id="call2" src="added programatically" controls type="audio/mpeg"></audio>

If this is not the case and div means exactly as is, then you should change your HTML structure and make use of the above mentioned.如果不是这种情况并且 div 的含义完全一样,那么您应该更改您的 HTML 结构并利用上述内容。 Here's an example:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio这是一个示例:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio

Otherwise the URL generated for the source is not correct.否则为源生成的 URL 不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM