使用SoundPool连续播放片段

发布于 2024-11-30 04:55:29 字数 1109 浏览 0 评论 0原文

我为 Android 平板电脑创建了一款游戏,玩家可以在其中解决简单的数学问题。我正在努力让游戏大声朗读每个问题。我有所有数字 0-9 和 20、30、40 等的声音剪辑录音。有了所有这些声音剪辑,我应该能够“混合和匹配”它们以大声朗读任何可能的问题。这是我当前的 sayProblem() 方法:

    private void sayProblem() {
    if(soundBtn.isChecked() == true){
        Runnable sayRun = new Runnable() {
            public void run(){
                while(sp.play(numberClips[firstOperand - 1], 1, 1, 5, 0, 1) == 0);
                Log.i(myTag, "FirstOp said");
                while(sp.play(signClips[CURRENT_TYPE], 1, 1, 4, 0, 1) == 0);
                Log.i(myTag, "sign said");
                while(sp.play(numberClips[secondOperand - 1], 1, 1, 3, 0, 1) == 0);
                Log.i(myTag, "2ndOp said");
            }
        };

        Thread sayThread = new Thread(sayRun);
        sayThread.start();
    }
}

这在某些情况下可以正确读取问题,但有时在 3 个不同的剪辑组合在一起构成问题时会出现很长的延迟。 当它正常工作时,结果如下: “一加三”,当它不正确时,结果是这样的:

“一......................加.. .........................三”,其中句点代表不同长度的长停顿。

我想使用 while 循环继续调用 sp.play() 并不是让它连续播放三个声音剪辑的正确方法,但这是唯一让我接近的方法。

任何人都可以帮助我使用 SoundPool(或其他任何东西)更一致地连续播放三个剪辑吗?

I have created a game for Android Tablets where the player is solving simple math problems. I am working on making the game read each problem aloud. I have sound clip recordings of all of the numbers 0-9 and 20,30,40 etc.. With all of these sound clips I should be able to "mix and match" them to read any possible problem aloud. This is my current sayProblem() method:

    private void sayProblem() {
    if(soundBtn.isChecked() == true){
        Runnable sayRun = new Runnable() {
            public void run(){
                while(sp.play(numberClips[firstOperand - 1], 1, 1, 5, 0, 1) == 0);
                Log.i(myTag, "FirstOp said");
                while(sp.play(signClips[CURRENT_TYPE], 1, 1, 4, 0, 1) == 0);
                Log.i(myTag, "sign said");
                while(sp.play(numberClips[secondOperand - 1], 1, 1, 3, 0, 1) == 0);
                Log.i(myTag, "2ndOp said");
            }
        };

        Thread sayThread = new Thread(sayRun);
        sayThread.start();
    }
}

This works some of the time to read the problem correctly but sometimes there will be really long delays between the 3 different clips that go together to make up a problem.
When it works correctly it comes out like this:
"one plus three", when it is incorrect it comes out like this:

"one .............................plus...........................three" where the periods represent long pauses of varying lengths.

I imagine using a while loop to keep calling sp.play() is not the correct way to get it to play three sound clips in succession but it is the only thing that has even gotten me close.

Can anyone help me out with using SoundPool (or anything else) to play three clips in succession more consistently?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文