Code Monkey home page Code Monkey logo

nspeex's Introduction

NSpeex

早在11-12年,由于一个游戏项目要使用到语音压缩库,当时选用了speex,我们当时使用的是Unity3D游戏引擎,由于市面上没有.Net平台下的speex的库,于是我便将jspeex翻译成NSpeex。但是后来由于种种原因不再维护项目,前段时间有人问我这个库该怎么用,我就使用别人的NSpeex库来进行解释说明,毕竟我之前的代码太像Java风格了,于是我将别人的代码复制过来,自己写点文档方便别人

例子(example)

见 Test/SpeexTest.cs,将male.wav 转化为result.spx文件,然后使用foobar播放器可以播放

编码(encode)

// byte[] dataIn -> byte[] dataOut
// convert to short
short[] data = new short[dataIn.Length / 2];
Buffer.BlockCopy(dataIn, 0, data, 0, dataIn.Length);
byte[] dataOut = new byte[dataIn.Length];
int encSize = speexEncoder.Encode(data, 0, data.Length, dataOut, 0, dataOut.Length);
if(encSize > 0){
    // encode success
    // todo with dataOut[0-encSize]
}

解码(decode)

// byte[] dataIn -> byte[] dataOut
short[] data =  new short[1024];
int decSize = speexEncoder.Decode(dataIn, 0, dataIn.Length, data, 0, false);

if(decSize > 0 ){
    byte[] dataOut = new byte[1024];
    Buffer.BlockCopy(data, 0, dataOut, 0, decSize);
    // todo with dataOut[0-decSize]
}

nspeex's People

Contributors

aijingsun6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nspeex's Issues

Random decoded error

Hi,
i'm trying to write here because i have an issue that have been stopping the dev of my app for weeks.

I'm writing a realtime voice chat application, with a centralized server (dedicated) architecture, using C# (dedicated server is a .net core app while for the client i'm using C# to script the game engine Unity3D).

For the encoding/decoding part i'm using NSpeex.

Basically, it works like this:

  • Client records from the microphone/soundcard PCM samples and put them in chunks of X samples each.

  • These chunks are then passed to the encoder, when one chuck has been encoded (async on another thread) a callback is received and the compressed [] is put in a queue for the network

delivery. Each chunk is 554 bytes.

  • The dedicated server receives the data and broadcasts to other clients (TCP stream).

  • The client receives the chunk and makes the opposite: every byte received is put in a List which is the first buffer.

When i've got enough bytes to start decoding (554 bytes), the segment is taken and sent to the decoder.

Once it has been decoded, i take the resulting PCM samples and pass them to the playing buffer which sends them to the soundcard when i have enough data to start playing.


Now, it works GOOD! Most of the time...

but from time to time, out of the blue and totally random, the decoder (and only the decoder) throws an Exception like: "more than two sidebands found" or "invalid sideband mode" and

simply stops working, making my app unable to continue working.

From my understanding of the Speex library, this means that the decoder doesn't find the bits where it expect them to be... but WHY it happens only from time to time?!

I've seen it happen when i feed the encoder/decoder with segments of the wrong size but in this case i've debugged the hell out of it and i'm sure i'm passing always the same data amount.

..could this be a network related problem? I don't think so, i'm using reliable TCP and i'm sure every packet reachs the destination and in the correct order.

What could it be? How should i proceed to debug the problem further?

Thanks in advance,
Davide

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.