如何使用 VoiceXML 播放文件夹中的多个文件?

发布于 2024-12-06 06:20:44 字数 1005 浏览 0 评论 0原文

对于一个特定的项目,我试图编写一个 voicexml 文件来播放一些音频文件。我播放文件没有问题。但我需要一些播放文件夹中多个文件的说明。我知道我必须使用 ecmascript 和标签来做到这一点。但我不知道如何访问文件夹来播放特定的 wav 文件。

这是我播放 1 个音频文件的代码:

<?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>

我有一个包含不同 .wav 文件的文件夹。

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

我怎样才能播放所有这些而不需要一一调用它们,因为任何人都可以自定义这个 wav 文件。我只需要扫描文件夹并使用 VoiceXML 播放它们即可。

如果有任何建议,我将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-12-13 06:20:44

首先,VoiceXML 无法扫描该文件夹。
它需要其他编程语言。

例如(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 是称为子对话框。

<?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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文