我有一個返回字節數組的Web服務,我的意圖是將所述數組轉換爲客戶端(如Blackberry等手持設備)中的.wav。然而,我真的不知道如何做到這一點,我試圖做一個FileOutputStream,但當然不會玩。所以我再次不知道該怎麼做。有任何想法嗎?將字節數組轉換爲.wav java
1
A
回答
2
所以,也有.WAV格式的地段,這裏的一些文檔:
- http://en.wikipedia.org/wiki/WAV
- http://ccrma.stanford.edu/courses/422/projects/WaveFormat/(注尾數變化)
- http://www.lightlink.com/tjweber/StripWav/WAVE.html
這不只是一個流數據字節,但它很接近...只是有點頭,你應該很好。
我想你也可以使用類似的方式爲Web服務和設備上的媒體播放器之間被破壞的數據http://java.sun.com/j2se/1.5.0/docs/api/javax/sound/sampled/spi/AudioFileWriter.html
0
*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bemukan.voiceRecognition.speechToText;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
*
* @author MuhammedYC
*/
public class SplitAudio {
private int BUFFER_LENGTH=1024;
private double startTime;
private double endTime;
private File sourceFile;
public SplitAudio(File sourceFile,int startTime,int endTime){
this.startTime=startTime;
this.endTime=endTime;
this.sourceFile = sourceFile;
AudioInputStream inputAIS = null;
try {
inputAIS = AudioSystem.getAudioInputStream(sourceFile);
Clip clip = AudioSystem.getClip();
clip.open(inputAIS);
long totalMicroSecond = clip.getMicrosecondLength();
} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
} catch (LineUnavailableException e) {
}
}
public void splitAudio(){
File outputFile = new File("a.wav");
AudioFileFormat fileFormat = null;
try {
fileFormat = AudioSystem.getAudioFileFormat(sourceFile);
AudioFileFormat.Type targetFileType = fileFormat.getType();
AudioFormat audioFormat = fileFormat.getFormat();
AudioInputStream inputAIS = AudioSystem.getAudioInputStream(sourceFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int nBufferSize = BUFFER_LENGTH * audioFormat.getFrameSize();
byte[] abBuffer = new byte[nBufferSize];
while (true) {
int nBytesRead = inputAIS.read(abBuffer);
if (nBytesRead == -1) {
break;
}
baos.write(abBuffer, 0, nBytesRead);
}
/* Here's the byte array everybody wants.
*/
byte[] abAudioData = baos.toByteArray();
// double baslangic = abBuffer.length * oranBaslangic;
// double bitis = abBuffer.length * oranSon;
byte[] splittedAudio = new byte[(int) (endTime - startTime)];
for (int i = 0; i < (int) (endTime- startTime); i++) {
splittedAudio[i] = abAudioData[i + (int) startTime];
}
ByteArrayInputStream bais = new ByteArrayInputStream(splittedAudio);
AudioInputStream outputAIS = new AudioInputStream(bais, audioFormat,
splittedAudio.length/audioFormat.getFrameSize());
AudioSystem.write(outputAIS, targetFileType, outputFile);
} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
}
}
}
相關問題
- 1. NAudio將字節數組轉換爲Wav
- 2. 將wav音頻格式字節數組轉換爲浮點數
- 3. 將.wav轉換爲數組
- 4. 如何將.wav文件轉換爲字節數組?
- 5. 將Java字節數組轉換爲Python字節數組
- 6. 如何將Java字節數組轉換爲Scala字節數組?
- 7. 將字節數組轉換爲Wav文件
- 8. 將PCM原始字節轉換爲WAV字節
- 9. 如何將g729編碼的字節數組轉換爲Java中的.wav pcm_alaw?
- 10. 將Java字符串轉換爲16字節的字節數組
- 11. 如何將字符串數組轉換爲字節數組? (java)
- 12. 將void *轉換爲字節數組
- 13. Java - 將音頻的字節數組轉換爲整數數組
- 14. Python將數組轉換爲Wav
- 15. 轉換字節數組爲java類型
- 16. 將字符串數組(字節值)轉換爲字節數組
- 17. 將byte []數組轉換爲字節數
- 18. 將樣本轉換爲字節數組
- 19. BigInteger如何在Java中將字節數組轉換爲數字?
- 20. 如何字節數組轉換爲WAV文件<OOURAFFT>
- 21. 將字節數組轉換爲字符串的字節數
- 22. Java:將字節轉換爲整數
- 23. 將PNG壓縮字節數組轉換爲BMP字節數組
- 24. 將三維字節數組轉換爲單字節數組
- 25. 將NSData轉換爲base64encoded並將字節數組轉換爲C#
- 26. 將字節數組轉換爲uint64_t?
- 27. 將C#字節數組轉換爲VB.NET
- 28. 將對象轉換爲字節數組
- 29. 將字節數組轉換爲pdf
- 30. 將位圖轉換爲字節數組
有面積數。您可能希望向我們提供有關您正在執行的操作的更多詳細信息,包括設備上運行的代碼。 – 2009-04-08 19:47:57