我从以前问过的有关将mp3文件添加到我的javascript代码中的问题中获得建议,并提出了这个建议。
var howrutday = new Audio('file:///C:/This_PC/Music/Science_Fair_Robot/howrutday.mp3');
var name = function (robot) {
if ('Hi.' + 'Hi!' + 'Hello.' + 'Hello!' + 'Greetings.' + 'Greetings!') {
console.log("How are you doing today " + name + "?");
howrutday.play();
} else if ('Good morning.' + 'Good morning!') {
console.log("How are you doing today " + name + "?");
} else if ('Good afternoon.' + 'Good afternoon!') {
console.log("And to you also, what a lovely day.");
} else if ('Good evening.' + 'Good evening!') {
console.log("How was your day?");
} else if ('Good night.' + 'Good night!') {
console.log("Rest well " + name + ". I hope to see you tomorrow.");
} else {
console.log("Try saying that again but make sure you are using proper grammar like applying punctuation and capitalization.");
}
我不确定语法是否有问题,或者是否没有使音频文件对程序可见。也有人建议网站运行我的代码,因为也许我正在使用的那个网站不播放音频。虽然只是一个理论。
最佳答案
我想请您回答here的问题。
var audio = new Audio('audio_file.mp3');
audio.play();
那是播放音频的基础。稍后从Roko C. Buljan提供的链接中播放音频后,看看条件
关于javascript - Javascript:为什么音频不播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33726349/