2013-10-04 69 views
0

我試圖在我的動作項目中將wav轉換爲mp3,我很高興找到https://github.com/phillockwood/Shine-MP3-Encoder-on-AS3-Alchemy 但我的動作知識非常有限,我不知道如何在我的項目中使用它。如何使用「Shine-MP3-Encoder-on-AS3-Alchemy」?

在我的項目,功能如下,ByteArray的數據轉換成WAV格式,我需要將WAV轉換成MP3。我知道用個服務式MP3編碼器可以做這個工作,但我不知道在哪裏把它放在我的項目,以及如何將它的功能...誰可以幫我嗎?我也很欣賞它~~

public static function convertToWav(soundBytes:ByteArray, sampleRate:int):ByteArray { 
     var data:ByteArray = new ByteArray(); 
     data.endian = Endian.LITTLE_ENDIAN; 

     var numBytes:uint = soundBytes.length/2; // soundBytes are 32bit floats, we are storing 16bit integers 
     var numChannels:int = 1; 
     var bitsPerSample:int = 16; 

     // The following is from https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ 

     data.writeUTFBytes("RIFF"); // ChunkID 
     data.writeUnsignedInt(36 + numBytes); // ChunkSize 
     data.writeUTFBytes("WAVE"); // Format 
     data.writeUTFBytes("fmt "); // Subchunk1ID 
     data.writeUnsignedInt(16); // Subchunk1Size // 16 for PCM 
     data.writeShort(1); // AudioFormat 1 Mono, 2 Stereo (Microphone is mono) 
     data.writeShort(numChannels); // NumChannels 
     data.writeUnsignedInt(sampleRate); // SampleRate 
     data.writeUnsignedInt(sampleRate * numChannels * bitsPerSample/8); // ByteRate 
     data.writeShort(numChannels * bitsPerSample/8); // BlockAlign 
     data.writeShort(bitsPerSample); // BitsPerSample 
     data.writeUTFBytes("data"); // Subchunk2ID 
     data.writeUnsignedInt(numBytes); // Subchunk2Size 

     soundBytes.position = 0; 
     while(soundBytes.bytesAvailable > 0) { 
      var sample:Number = soundBytes.readFloat(); // The sample is stored as a sine wave, -1 to 1 
      var val:int = sample * 32768; // Convert to a 16bit integer 
      data.writeShort(val); 
     } 

     return data; 
    } 

回答

1

我這樣做:

  • 使用(ghostcat.media.WAVWriter)將聲音轉換成字節組爲WAV

  • 使用光澤CONVER這個wav bytearray到mp3文件

查看那個WAVWriter插件,這讓事情變得很簡單對我來說