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…
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
But my multiPlayer game not based on Unity networking i want chat with teamSpeak or redbox
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…
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.
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.
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.
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)
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.
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!
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.
so is this voice chat real time that you accomplished over unity networking?
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.
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.
I already have it working in my game here:
I’m working on an asset which enables voice chat for webplayer and standalone builds: http://forum.unity3d.com/threads/144490-Announce-Voice-Chat-VOIP
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
Check my sig for a link.
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.
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.