"unty stream microphone+" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "unty stream microphone+" answered properly. Developers are finding an appropriate answer about unty stream microphone+ related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like unty stream microphone+. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on unty stream microphone+. 

unty stream microphone+

By CirexCirex on Dec 18, 2020
int lastSample = 0;
void FixedUpdate()
{
    // If there is a connection
    if (Network.connections.Length > 0)
    {
        if (notRecording)
        {
            notRecording = false;
            sendingClip = Microphone.Start(null, true, 100, FREQUENCY);
            sending = true;
        }
        else if(sending)
        {
            int pos = Microphone.GetPosition(null);
            int diff = pos-lastSample;

            if (diff > 0)
            {
                float[] samples = new float[diff * sendingClip.channels];
                sendingClip.GetData (samples, lastSample);
                byte[] ba = ToByteArray (samples);
                networkView.RPC ("Send", RPCMode.Others, ba, sendingClip.channels);
                Debug.Log(Microphone.GetPosition(null).ToString());
            }
            lastSample = pos;
        }
    }
}

[RPC]
public void Send(byte[] ba, int chan) {
    float[] f = ToFloatArray(ba);
    audio.clip = AudioClip.Create("", f.Length, chan, FREQUENCY,true,false);
    audio.clip.SetData(f, 0);
    if (!audio.isPlaying) audio.Play();

}
// Used to convert the audio clip float array to bytes
public byte[] ToByteArray(float[] floatArray) {
    int len = floatArray.Length * 4;
    byte[] byteArray = new byte[len];
    int pos = 0;
    foreach (float f in floatArray) {
        byte[] data = System.BitConverter.GetBytes(f);
        System.Array.Copy(data, 0, byteArray, pos, 4);
        pos += 4;
    }
    return byteArray;
}
// Used to convert the byte array to float array for the audio clip
public float[] ToFloatArray(byte[] byteArray) {
    int len = byteArray.Length / 4;
    float[] floatArray = new float[len];
    for (int i = 0; i < byteArray.Length; i+=4) {
        floatArray[i/4] = System.BitConverter.ToSingle(byteArray, i);
    }
    return floatArray;
}

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on unty stream microphone+ can get a collection of related answers to their query. Programmers need to enter their query on unty stream microphone+ related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about unty stream microphone+ for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of unty stream microphone+ while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "unty stream microphone+". Visit this developer's friendly online web community, CodeProZone, and get your queries like unty stream microphone+ resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "unty stream microphone+"

View All Whatever queries

Whatever queries related to "unty stream microphone+"

Browse Other Code Languages

CodeProZone