Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Android Microphone spitting sound.

Discussion in 'Android' started by Toony, May 30, 2012.

  1. Toony

    Toony

    Joined:
    May 30, 2012
    Posts:
    2
    Hello,
    I want to launch the microphone in a simple project. My code work in IOS/Windows Standalone but doesn't work in Android. The sound is like spitting. :(
    They have some special way to launch the microphone in Android or Microphone doesn't work in any android device ?

    In my scene, i have a Audio source in the main camera with checkbox Loop set to true.
    And I put this in a Samsung galaxy spica with android 2.1 and a HTC H2 root in a Android 2.2.

    My code :
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Play_Microphone : MonoBehaviour {
    6.  
    7.  
    8.     private bool m_WaitForMicReady = false;
    9.     private bool m_MicLaunched = false;
    10.  
    11.     private bool m_StartVoice = false;
    12.  
    13.    
    14.     // Use this for initialization
    15.     void Start () {
    16.            
    17.     }
    18.    
    19.     // Update is called once per frame
    20.     void Update () {
    21.  
    22.         if (m_WaitForMicReady)
    23.         {
    24.             print("Microphone not yet Ready : " + Microphone.GetPosition(Microphone.devices[0]));
    25.             if (Microphone.GetPosition(Microphone.devices[0]) > 0)
    26.             {
    27.                 audio.Play();
    28.                 m_WaitForMicReady = false;
    29.             }
    30.         }
    31.  
    32.         if (m_StartVoice)
    33.         {
    34.  
    35.             if (!m_MicLaunched)
    36.             {
    37.                 audio.clip = Microphone.Start(Microphone.devices[0], true, 3, 44100);
    38.                 m_WaitForMicReady = true;
    39.                 m_MicLaunched = true;
    40.             }
    41.         }
    42.  
    43.     }
    44.  
    45.     void OnGUI()
    46.     {
    47.         GUI.Label(new Rect(150, 25, 150, 25), Microphone.GetPosition(Microphone.devices[0]).ToString());
    48.         GUI.Label(new Rect(150, 50, 150, 50), Microphone.IsRecording(Microphone.devices[0]).ToString());
    49.  
    50.         if(GUI.Button(new Rect (150,100,150,50),!m_StartVoice?"PressMe":"StopMe"))
    51.         {
    52.             if(!m_StartVoice)
    53.                 m_StartVoice = true;
    54.             else
    55.             {
    56.                 Microphone.End(Microphone.devices[0]);
    57.                 audio.Stop();
    58.                 m_StartVoice = false;
    59.                 m_MicLaunched = false;
    60.                 m_WaitForMicReady = false;
    61.             }
    62.         }
    63.  
    64.         int i = 0;
    65.         foreach(string s in Microphone.devices)
    66.         {
    67.             GUI.Label(new Rect(150, 200 + (i * 50), 150, 50), s);
    68.             i++;
    69.         }
    70.     }
    71. }
    72.  
    Anyone can see what happen ?
    Thanks.
     
  2. ameralay

    ameralay

    Joined:
    May 6, 2014
    Posts:
    3
    I have this problem too :( any ideas?