我本质上试图构建的是一个可自我读取的网站,并在使用鼠标时提供可听见的反馈。耳塞的使用方式与大多数用户使用视觉图标的方式类似。预先录制的口语曲目用于已知元素,例如我的导航栏菜单。我在大多数浏览器中都将E-Speak用于tts,但计划在IE中使用tts Web服务,因为E-Speak在IE中不起作用。传统上,盲人用户会通过击键来导航站点。但是,我是一名正在接受培训的网络开发人员,并且通过使用声音作为校对布局的辅助手段来推销信封[即,我的div是否正确 float ?图像是否位于正确的div中?我可以通过四处浏览和收听来检查这一点。这是一种破坏性技术,与使用更传统的读取解决方案相比,它试图给您的大脑更多的信任。
我已经待了好几个星期了,仍然无法预加载所有声音。我求助于一种递归函数,从理论上讲,直到第一个声音对象加载后,它才会创建下一个声音对象。我的十八个听筒正在按期望的事件加载和正确播放,但是我的12条口述曲目中只有三个似乎正在加载-或,如果正在加载,则它们不在播放。
这是我两个相关模块的代码。你们中有人想出一种可靠的预加载多种声音的方法吗?
var Earcons = (function() {
// Earcons are like icons, but use symbolic sounds instead of pictures
var trackUrls = [
"audio/newpage.mp3", "audio/fgrow.mp3", "audio/fshrink.mp3",
"audio/slideright.mp3", "audio/slideleft.mp3", "audio/sdiv.mp3", "audio/tell.mp3",
"audio/office_lobby.mp3", "audio/footstep.mp3", "audio/apple.mp3",
"audio/typewriter.mp3",
"audio/walking.mp3", "audio/macspeak.mp3", "audio/picklock1.mp3",
"audio/gossip.mp3", "audio/winenter.mp3", "audio/winleave.mp3", "audio/beep.mp3"];
var trackTitles = [
"soundOnLoad", "soundOnGrow", "soundOnShrink", "soundOnSlideRight",
"soundOnSlideLeft", "soundOnDiv", "soundOnParagraph", "work",
"soundOnList", "apple", "stype", "walk", "macbook",
"soundOnLink", "soundOnInput", "winenter", "winleave", "soundOnImage"];
var trackPtr = 0;
var getTrackNumber = function (trackName) {
for (i = 0; i < trackTitles.length; i++) {
if (trackName == trackTitles[i]) return i;
}
return -1;
};
var preload = function() {
if (trackPtr >= trackUrls.length)
{ trackPtr = 0; return; }
var trackId = "st" + trackPtr + "";
var trackUrl = trackUrls[trackPtr];
trackPtr++;
var soundTrack = soundManager.createSound ({stream: false,
id: trackId,
url: trackUrl,
autoLoad: false, autoPlay: false});
soundTrack.load ({onload: function() { preload(); } });
};
var unload = function() {
for (i = 0; i < trackUrls.length; i++) {
var soundTrack = soundManager.getSoundById ("st" + i);
soundTrack.unload();
soundTrack.destruct();
}
};
interface = {
trackUrls: trackUrls,
trackTitles: trackTitles,
getTrackNumber: getTrackNumber,
preload: preload,
unload: unload
};
return interface;
} )();
var Narrations = (function() {
var trackUrls = [
"audio/about.mp3", "audio/webtech.mp3", "audio/screenreader.mp3",
"audio/services.mp3", "audio/stories.mp3", "audio/settings.mp3",
"audio/feedback.mp3", "audio/display.mp3", "audio/soundset.mp3",
"audio/voiceset.mp3", "audio/divmain.mp3", "audio/divcenter.mp3",
"audio/divnav.mp3"];
var trackTitles = [
"About This Web App", "Web Development Technologies", "What's A Screen Reader",
"Services I Can Offer", "Stories, Poetry, Anecdotes", "Settings",
"Send Me Your Comments", "Display Settings", "Sound Settings",
"Voice Quality Settings", "div mainContent", "div center", "div navBar"];
var trackPtr = 0;
var getTrackNumber = function (trackName) {
for (i = 0; i < trackTitles.length; i++) {
if (trackName == trackTitles[i]) return i;
}
return -1;
};
var preload = function() {
if (trackPtr >= trackUrls.length)
{ trackPtr = 0; return; }
var trackId = "vt" + trackPtr + "";
var trackUrl = trackUrls[trackPtr];
trackPtr++;
var voiceTrack = soundManager.createSound ({stream: false,
id: trackId,
url: trackUrl,
autoLoad: false, autoPlay: false});
voiceTrack.load ({onload: function() { preload(); } });
};
var unload = function() {
for (i = 0; i < trackUrls.length; i++) {
var voiceTrack = soundManager.getSoundById ("vt" + i);
voiceTrack.unload();
voiceTrack.destruct();
}
};
interface = {
trackUrls: trackUrls,
trackTitles: trackTitles,
getTrackNumber: getTrackNumber,
preload: preload,
unload: unload
};
return interface;
})();
播放耳朵缺点的功能:
var playSound =函数(trackName){
var trackID =“st” + Earcons.getTrackNumber(trackName)+“”;
var soundTrack = soundManager.getSoundById(trackID);
如果(!soundTrack)返回;
如果(沉默)返回;
如果(soundManager.playState> 0)soundManager.stopAll();
soundTrack.play();
};
以及播放语音录音:
函数playSpeech(录制){
var tn = Narrations.getTrackNumber(记录);
如果(tn == -1)返回false;
var voiceId =“vt” + tn +“”;
var voiceTrack = soundManager.getSoundById(voiceId);
如果(!voiceTrack)返回false;
如果(soundManager.playState> 0)soundManager.stopAll();
soundManager.onready(function(){voiceTrack.play();});
返回true;
} //结束playSpeech
如果我将播放功能方法设为[[] Earcons.playSound(),Narrations.playSpeech(),这一切可能会更好吗?
您可以在以下位置体验我的网站的运作部分:
www.innovascripter.com
预先感谢您的任何见解:-)
最佳答案
IE 9具有硬件和资源确定的限制,可以一次加载多少个音频标签。我正在研究SoundJS,我们在documentation中包括有关此限制和其他限制的说明。
SoundJS有两个解决方法,最近实现的audio sprites和强制执行Flash回退的较旧解决方案。
希望能有所帮助。
关于javascript - soundManager2:无法从Urls阵列中预加载我的所有声音,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22976640/