0

我试图在我的 actionscript 项目中将 wav 转换为 mp3,我很高兴找到https://github.com/phillockwood/Shine-MP3-Encoder-on-AS3-Alchemy 但我的 actionscript 知识非常有限,我不知道如何在我的项目中使用它。

在我的项目中,函数如下,将 byteArray 数据转换为 wav 格式,我需要将 wav 转换为 mp3。我知道使用 Shine-MP3-Encoder 可以完成这项工作,但我只是不知道在我的项目中放置它的位置,以及它的功能......谁能帮助我?我很感激~~

    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;
    }
4

2 回答 2

1

I did this:

  • Use (ghostcat.media.WAVWriter) to convert a sound bytearray to a wav

  • Use shine to conver this wav bytearray to an mp3 file

Look up that WAVWriter plugin, that made things really easy for me

于 2013-10-15T03:57:28.420 回答
-1

您可以将此示例与“encodeClicked()”函数一起使用

https://github.com/cyrildiagne/Shine-MP3-Encoder-on-AS3-Alchemy/blob/master/src/fr/kikko/test/ShineMP3EncoderTest.as

于 2019-06-26T14:02:36.797 回答