gpt4 book ai didi

java - 将声音文件链接到字符串值

转载 作者:行者123 更新时间:2023-11-30 03:14:31 25 4
gpt4 key购买 nike

private String sL[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z", "ç", "à", "é", "è", "û", "î" };

尽管该代码有效。我真的不想要它。我希望每个按钮都能发出不同的声音。所以要在 Java 中发出声音,你需要一些东西 like that

public class MyActivity extends Activity {
...
protected void onStart() {
super.onStart();
MediaPlayer mp = MediaPlayer.create(this, R.raw.sound_file_1);
mp.start();
}
...
}

我每个字母都有一个 wav 文件,所以 a 应该播放 a.wav 等等。我希望创建一个从 a 到 z 的循环并以这种方式播放每个 wav

它并不是真正的 onStart(),它更像是每当按下按钮时播放不同的声音,但这不是重点。我想为该字符串的每个元素传递不同的声音。

最佳答案

为什么不直接使用您创建的数组?

 For(int i = 0; i< sL.length; i++){
String wavFileName = sl[i] + ".wav";
// do whatever you need to do here
}

对于按需(按下按钮获得特定声音),Jeroen 使用 map 的想法将会奏效。

关于java - 将声音文件链接到字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20364893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com