質問

For a specific project, I am trying to write a voicexml file to play out some audio files. I have no problem about playing an file. But I need some directions for playing multiple files in a folder. I know I have to use ecmascript and tag to do this. But I can't figure out how to access a folder to play the specific wav files.

Here is my code to play 1 audio file:

<?xml version="1.0" encoding="UTF-8"?> 
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml" xml:base="file://">
<var name="repeat" expr="session.user.repeat"/>
<form id="loopblock">
    <block>
        <if cond="repeat > 0">
        <prompt>
            <audio src="file://provisioned/music.wav"/>
        </prompt> 
        <assign name="repeat" expr="repeat - 1"/>
        <goto next="#loopblock"/>
        </if>
        <disconnect/>
    </block>
</form>
</vxml>

I have a folder which includes different .wav files.

  • /provisioned/music/a.wav
  • /provisioned/music/b.wav
  • /provisioned/music/c.wav

How can I play all of them without calling them one by one because anyone can customize this wav file. All I need to scan the folder and play them out with VoiceXML.

I'd be appreciated for any suggestion.

役に立ちましたか?

解決

At First, VoiceXML can't scan the folder.
It needs other programming language.

For example(JSP - http://localhost:8080/example/get_audio_list.jsp)

<?xml version="1.0" encoding="UTF-8"?>
<%
String audioListCSV = "";
File[] audioList = new File("/provisioned/music/").listFiles();
for (int i = 0; i < audioList.length; ++i) {
    File audio = audioList[i];
    if (audio.isFile()) {
        audioListCSV += "\'file:///" + audio.getAbsolutePath() + "\'";
        if (i + 1 < audioList.length) {
            audioListCSV += ",";
        }
    }
}
%>    
<vxml version="2.1">
    <form>
        <block>
            <var name="audioList" />
            <assign name="audioList" expr="[<%=audioListCSV%>]" />
            <return namelist="audioList" />
        </block>
    </form>
</vxml>

JSP is called subdialog.

<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1">
    <script>
        var audioList;
    </script>
    <form id="getAudioList">
        <subdialog name="get_audio_list" src="http://localhost:8080/example/get_audio_list.jsp">
            <filled>
                <assign name="audioList" expr="get_audio_list.audioList">
                <goto next="#playAudioList" />
            </filled>
        </subdialog>
    </form>
    <form id="playAudioList">
        <block>
            <prompt bargein="true">
                <foreach item="i" array="audioList">
                    <audio expr="i" />
                </foreach>
            </prompt>
        </block>
        <block>
            <disconnect />
        </block>
    </form>
</vxml>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top