5

I want to play *.spx files which encoded by Speex on the Web.
But I have no knowledge of Flash/Flex or any Flash Audio codec. After Google search for a whole day, I got some solutions, that is:

  1. Do something wrapping Speex files with a FLV container because that the Speex is only playable as the audio codec in a FLV container.
    Now I can play a SPX-Audio-Only FLV file in Flex, I use netStream.play("audio-only-speex.flv"), But I donot know how to wrap a Spx file with FLV container using ActionScript.
    Any example project?

  2. Decode Spx using AS.
    I checked out the fllowing pages that they all decoded OGG Vorbis but no Speex :(
    http://barelyfocused.net/blog/2008/10/03/flash-vorbis-player
    http://www.exswap.com/?p=132
    http://mauft.com/2010/11/ogg-vorbis-in-flash
    Adobe also provides a AS3 OggVorbis Library which ported by Alchemy:
    http://labs.adobe.com/wiki/index.php/Alchemy:Libraries

  3. FMS: do a server streaming using FMS or Red/Xuggle. I have never heard FMS stuffs before, as well as I'm not sure whether my virtual host can support or not...

  4. Convert every Spx files to MP3.

I think the best solution is decoding Spx in AS3, Yes, I'd like to make a Spx Flash Player.

So, I downloaded Speex Library from speex.org, installed Adobe Alchemy. After ./configure;make the libspeex, build libspeex/speex.c out a libspeex.swc via Alchemy. then, I donot know how to do next. How can I decode the speex audio with AS3?
My libspeex.swc: http://demo.0x123.com/libspeex.swc

In addtion, should I rewrite the libspeex using Alchemy API before build the libspeex.swc?

Although I am not professional in AS, but I have a strong ability to learn. Any advice will be greatly appreciated, Thanks very much.

kapex
  • 28,903
  • 6
  • 107
  • 121
Elf Sundae
  • 1,575
  • 16
  • 23
  • I'm not sure about future compatibility of alchemy: http://ncannasse.fr/blog/adobe_make_some_alchemy – kapex Dec 07 '11 at 13:47
  • @kapep: if you compile against FP 10.x, Alchemy will work in FP 11.x. To quote the [release notes](http://blogs.adobe.com/flashplayer/2011/09/updates-from-the-lab.html): `Existing Alchemy experiments targeting Flash Player 10.x and AIR 2.x are unaffected` – paleozogt Dec 08 '11 at 16:03
  • @kapep Thank you for editing my question, I do not have permission to add three more links. – Elf Sundae Dec 09 '11 at 02:08

2 Answers2

1

Adobe says specifically not to rely on Alchemy yet, so there's no official way to do it on the client side (as far as I know.) It's absurd given that there is clearly a speex decoder being used.

Can you use Xuggle's tricked-out version of ffmpeg (http://code.google.com/p/xuggle-ffmpeg/) to embed the speex in FLVs? If you can run xuggle in batch or on the fly, then regardless of the original audio format, you can serve a speex encoded FLV, playable from netStream.play.

ffmpeg -i test.wav -acodec libspeex -f flv -y speex.flv

For basic playing, you wouldn't even need a flash media server.

Ian McGraw
  • 571
  • 6
  • 9
  • Thank you very much, I've known how to convert spx to other formats file then server them or stream them, but I really wanna a directly speex codec for flash, to make a spx flash player, just like jwPlayer or Google's mp3 player :) Anyway, thank you for answering my question. – Elf Sundae Dec 10 '11 at 22:49
  • So you want to play speex without wrapping it in the FLV container? Are these speex files that you don't have control over? Anyway, it sounds like Adobe will get an official version of Alchemy out in 2012. They say it will be free for non-commercial use. – Ian McGraw Dec 11 '11 at 06:47
  • I can wrap these spx files using FMS/Red, but I just want to make a standalone flash player. I will try this :) – Elf Sundae Dec 11 '11 at 17:16
  • Yeah, I try to avoid Flash media servers too :-). After wrapping with Xuggle, I think using any web server should work... `netStream.play("http://my.web.server/speex.flv");`. I think jwPlayer support speex-wrapped FLVs too. – Ian McGraw Dec 11 '11 at 18:00
0

Now I've known that I must rewrite the speex library using alchemy API:
http://labs.adobe.com/wiki/index.php/Alchemy:Documentation:Developing_with_Alchemy:C_API
http://labs.adobe.com/wiki/index.php/Alchemy:Documentation:Developing_with_Alchemy:AS3_API

I've done a simple helloWorld. It is the first step that is troublesome. :)

Main.c

#include <stdio.h>
#include "AS3.h"

static AS3_Val addNumber(void* self, AS3_Val args)
{
        double num1 = 0.0;
        double num2 = 0.0;

        AS3_ArrayValue( args, "DoubleType, DoubleType",
                       &num1, &num2);

        double sum = num1 + num2;
        return AS3_Number(sum);
}

static AS3_Val helloString(void* self, AS3_Val args)
{
        char *str = "Hello, Alchemy!";
        return AS3_String(str);
}


int main ()
{

        // define the methods exposed to ActionScript
    // typed as an ActionScript Function instance
    AS3_Val addNumberMethod = AS3_Function(NULL, addNumber);
        AS3_Val helloStringMethod = AS3_Function(NULL, helloString);

    // construct an object that holds references to the functions
    AS3_Val result = AS3_Object("addNumber: AS3ValType, helloString: AS3ValType",
                                    addNumberMethod,
                                    helloStringMethod);

    // Release
    AS3_Release(addNumberMethod);
        AS3_Release(helloStringMethod);

    // notify that we initialized -- THIS DOES NOT RETURN!
    AS3_LibInit(result);

    // should never get here!
    return 0;

}


compile using $ main.c -O3 -Wall -swc -o HelloAlchemy.swc

AS code:

        import cmodule.HelloAlchemy.CLibInit;
        import mx.controls.Alert;

        private var loader:CLibInit;
        private var lib:Object;

        private function init():void
        {
            loader = new CLibInit;
            lib = loader.init();
        }
        protected function button1_clickHandler(event:MouseEvent):void
        {
            Alert.show(String(lib.addNumber(Number(3),Number(5)))); 
        }

        protected function helloStringButton_ClickHandler(event:MouseEvent):void
        {
            var str:String = String(lib.helloString());
            Alert.show(str);
        }
Elf Sundae
  • 1,575
  • 16
  • 23