Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Voice Chat

Discussion in 'Multiplayer' started by Ravikant Sharma, Jun 1, 2012.

  1. Ravikant Sharma

    Ravikant Sharma

    Joined:
    May 8, 2012
    Posts:
    34
    Hi Friends,....Sorry for my bad English... I made a Multiplayer game. In this game user can chat to everyone now i want to include voice chat in my game i don't have any idea. I see on unity forum it's possible by teamSpeak but no tutorial... I want some hint for start voice chat by teamSpeak...
     
  2. cod

    cod

    Joined:
    Nov 26, 2011
    Posts:
    267
    I'm trying to create a voice chat, too, using microphone.Start and playing it, but u need to send it to another player, so U have to send him a rpc and network.serialize
     
  3. Ravikant Sharma

    Ravikant Sharma

    Joined:
    May 8, 2012
    Posts:
    34
    But my multiPlayer game not based on Unity networking i want chat with teamSpeak or redbox
     
  4. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394

    I've done some work and have working voice chat....

    The problem is the audio clips are HUGE... even if I downsample (or record) at 8k.. and make it a mono 8 bit, 8k sample... 1 second = 8000 bytes... This is way to much for gameplay.

    I was able to get a .zip library working.. but it only shrunk the data a tiny bit.

    Is there anyway to encode wav data on the fly? To ogg.. or anything? mp3 would be 1/10th the size and would work fine...
     
  5. GeorgeRigato

    GeorgeRigato

    Joined:
    Jul 5, 2012
    Posts:
    58
    I've managed to record audio form a iOS Device, save it to Application.persistentdatapath as a .wav file and send it trough WWW to my webserver.

    The problem is as Carmine stated: The files are large. The clips recorded are 15 seconds long and result in 1,3 Mb.

    In a scenario that thousands of users record one clip and send it at the same instant, would create a huge queue at server's reception and probably make the project impraticable.
    If the files size were smaller, the transfer and processing times would be more compatible with the ammount of audio produced by the mass of users.

    So the question remains: Is it possible to save data from audioclip in a .ogg format? Or even take the already saved .wav file and convert it to a compressed format on the device?

    Best regards.
     
  6. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    I've played around with a .zip (for c#) and a couple of others. But I couldn't find anything that really crushed the file down.

    I did however downsample it myself. This is really easy to do. If you record at 44,100... you can downsample it to 8,000 (the lowest most devices can play) with a simple for loop and skipping every bunch of bytes.

    Also changing it yourself from float (4 bytes) to a byte (8 bit) before sending it cuts the size 1/4th :) You can do this really easily by just doing a for loop and multiplying by 127.
     
  7. GeorgeRigato

    GeorgeRigato

    Joined:
    Jul 5, 2012
    Posts:
    58
    Yup, I am recording it at 44,100. I will try downsample it right now, but really don't know if doing so will solve the issue and/or create others like worse audio quality when playing it.

    Thanks for the instant reply.
     
  8. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    You'd be surprised, for VOICE it's totally fine.... basically humans can only generate between 5k to 6k with normal speaking voice (not singing.. just talking). So you would record at double that (12k) ... the reason CDs are 44.1 is because violins can get up to 22k.

    For kicks... just take the size of your sample, divide by 4, and take every 4th sample (go from 44,100 to 11,025) you can also literally just play it back at the 11k (you don't need to upsample it)
     
  9. GeorgeRigato

    GeorgeRigato

    Joined:
    Jul 5, 2012
    Posts:
    58
    Well, it dropped the file size to 240 Kb. But the quality loss is noticeable, at least running on the computer. Will test it on the device, as the audio reproducing on it is worse.

    Maybe recording it at 12k would be a good balance between size and quality. I will run some more tests.
     
  10. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    Just so you know some devices don't support RECORDING at anything other than 44k. I have a pair of USB headphones that can only record at 44 but playback at whatever. Good luck! Keep us posted!
     
  11. GeorgeRigato

    GeorgeRigato

    Joined:
    Jul 5, 2012
    Posts:
    58
    Just recorded at 12k with an iphone 4. Everything ok. Uploaded to my webserver, wich converts the .wav to .mp3, downloaded the file again and played it with no trouble. The final quality of the recording is no crystal-clear-CD-quality but I think its passable for the purpose.

    Great workaround that Carmine suggested, as it would be really hard to implement and set up a converter or save the audio at a compressed format.

    I really thank you, man.
     
  12. rstorm000

    rstorm000

    Joined:
    Aug 19, 2010
    Posts:
    229
    so is this voice chat real time that you accomplished over unity networking?
     
  13. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    I didn't specifically use Unity networking. But the networking doesn't matter... it's just sending the voice data so where you use Unity's networking or Photon Cloud or PlayerIO etc.

    You can play with it yourself by recording the mic, sending the data to someone else and then playing it back.
     
  14. azterixny

    azterixny

    Joined:
    Sep 3, 2009
    Posts:
    13
    The Teamspeak SDK library works with Unity Pro on native clients, but requires a good bit of integration work to get it set up. I would suggest downloading the Teamspeak SDK and running through the C# samples they provide. Then start reading up on how plugins work in Unity (very close to the way the Teamspeak C# samples show).

    I have successfully gotten a TS3 SDK-based client running in Unity, but am not at liberty to share source at this time. Outside of that, let me know if you have any specific questions and I'll try to answer them.
     
  15. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    I already have it working in my game here:

    http://www.snagen.com
     
  16. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
  17. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    I, too, am working on a voice chat solution for Unity. It is compatible with Webplayer, Standalone, and Mobile, as well as both Free and Pro. It uses the Speex audio codec to compress audio data, in addition to MuLaw, ADPCM, and any custom codec you wish to write. It also supports any networking engine, which you can handle with a simple interface implementation.
    It's been submitted to the asset store, and will probably be available within a few days.

    EDIT: It's now live :D Check my sig for a link.
     
    Last edited: Aug 21, 2013
  18. sdgd

    sdgd

    Joined:
    Jan 15, 2013
    Posts:
    81
    I'm thinking about this too, ... but I've came to conclusion you need big files in order for format to shrink them enough, ...

    WHAT ABOUT: if someone with enough technical knowledge would make a UNIQUE shrink from most commonly words we say and so on, and it would send on the fly the data already shrieked, but if data would be totally unique to the unique shrink than nothing would be compressed, ...

    if I'd knew assembly more I could do that but I don't know much even a little bit of it, ...

    and yes this unique shring compresser and decompresser would be pretty large I think.
     
  19. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    It's a little difficult to understand what you are saying, but I'll say this:

    Currently, there are a few widely-known ways of reducing audio data. There is the Speex audio codec, and there is SILK (which Skype recently open-sourced), among others. There's also Opus, but the code is the most arcane I've ever seen so would be difficult to port to C#. Speex has a pure C# .NET port known as NSpeex on CodeProject. SILK currently does not have a C# port, but I am working on one over at Google Code (SilkSharp).

    Those, at the moment, remain the most optimal compression algorithms you can find for audio.