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. Dismiss Notice

Audio Something strange when use UnityWebRequestMultimedia to load 16000 frequency mp3

Discussion in 'Audio & Video' started by ChaosVan, Dec 10, 2019.

  1. ChaosVan

    ChaosVan

    Joined:
    Dec 13, 2016
    Posts:
    12
    Code (CSharp):
    1. public class Test : MonoBehaviour
    2. {
    3.     public AudioClip clip;
    4.     public AudioSource source;
    5.     // Start is called before the first frame update
    6.     IEnumerator Start()
    7.     {
    8.         Debug.Log(string.Format("Play: len = {0}, channels = {1}, samples = {2}, frequency = {3}", clip.length, clip.channels, clip.samples, clip.frequency));
    9.  
    10.         UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip("file://" + Application.streamingAssetsPath + "/100013_123956000001_1575965491.mp3", AudioType.MPEG);
    11.         UnityWebRequestAsyncOperation ao = request.SendWebRequest();
    12.  
    13.         yield return ao;
    14.  
    15.         if (ao.isDone)
    16.         {
    17.             AudioClip ccc = DownloadHandlerAudioClip.GetContent(request);
    18.  
    19.             Debug.Log(string.Format("Play: len = {0}, channels = {1}, samples = {2}, frequency = {3}", ccc.length, ccc.channels, ccc.samples, ccc.frequency));
    20.  
    21.             source.PlayOneShot(ccc);
    22.         }
    23.     }
    24. }
    Here is a very simple code to load audio clip by UnityWebRequestMultimedia.GetAudioClip.

    The first line "public AudioClip clip" is an AudioClip file attached on the GameObject, and output Logs when Start.

    Then, I load a same audio file from StreamingAssetPath, when success, output a log too.

    I'm very sure, tow audio files are the same.

    Here is the logs, the first audioClip attached on game object is correct.
    But the second one, I load from disk, the length and samples are changed. 20191210173444.jpg

    I wonder WHY? I'm confused for days.

    It only shows on 16000 frequency mp3 file, 44100 is ok.

    20191210173536.jpg
     
  2. ChaosVan

    ChaosVan

    Joined:
    Dec 13, 2016
    Posts:
    12
    By the way, my unity is Unity2018.4.1f1.

    the 16000Hz test audio file is recorded by Microphone class, and convert to mp3 by lame-for-unity plugin