简体   繁体   English

使用java.sound API

[英]Using the java.sound API

I was looking into the Java sound API and noticed that it allows us to play audio files. 我正在研究Java声音API,发现它允许我们播放音频文件。 I have two questions. 我有两个问题。 Given an audio file, how can we use javax.sound to play the audio file at any random location. 给定一个音频文件,我们如何使用javax.sound在任意随机位置播放音频文件。 Moreover, does javax.sound convert audio files to text files containing their lyrics? 此外,javax.sound是否将音频文件转换为包含其歌词的文本文件?

"to play the audio file at any random location": “在任意随机位置播放音频文件”:

When you are creating an AudioInputStream object you can just give it the bytestream starting at the position at which you want to start like so: 在创建AudioInputStream对象时,可以给它字节流,从开始的位置开始,如下所示:

audioInputStream = new AudioInputStream( byteArrayInputStream, audioFormat,
    audioData.length/audioFormat.getFrameSize());

This is from the complete example-code at: http://www.developer.com/java/other/article.php/1565671/Java-Sound-An-Introduction.htm 这来自完整的示例代码,位于: http : //www.developer.com/java/other/article.php/1565671/Java-Sound-An-Introduction.htm

To your second question: There exist several speech-recognition packages but as far as i know they do a poor job at parsing music because there is too much "noise". 关于第二个问题:存在几种语音识别程序包,但据我所知,它们在解析音乐方面做得很差,因为“噪音”过多。

Given an audio file, how can we use javax.sound to play the audio file .. 给定一个音频文件,我们如何使用javax.sound播放音频文件..

If you'd read the JavaSound info page you'd have seen source that can play a sound. 如果您阅读过JavaSound信息页面,则会看到可以播放声音的源。

..at any random location? ..在任何随机位置?

Clip also provides setMicrosecondPosition(long) & setFramePosition(int) . Clip还提供了setMicrosecondPosition(long)setFramePosition(int) Feed a random number to either, and you're set to go. 向任意一个输入一个随机数,就可以开始了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM