Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Audio how to make AudioClip from stream.

Discussion in 'Audio & Video' started by GamePro, Mar 20, 2018.

  1. GamePro

    GamePro

    Joined:
    Jul 16, 2012
    Posts:
    36
    Hello guys. is there any way that i make audio clip from in coming stream .

    Stream stream ; // get the audio stream from amazon polly.

    i want to make Audio Clip from this Stream.

    please help.


    thanks
     
  2. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    is that a finite file hosted on your amazon polly ? ( whatever that is :)
    I'm thinking about adding this to the asset linked in my signature / but haven't started yet

    It would help if you first test whether the file is streamable from the link you enter into the demo scene ( downloadable from the link in th asset description on the asset store )
    ( Not every networked resource access is supported )
     
  3. Lampogolovii_

    Lampogolovii_

    Joined:
    Aug 28, 2017
    Posts:
    12
    Hey,
    Have a problem with the listening from the audio stream.
    Using this code:

    Code (CSharp):
    1.     public void Play()
    2.     {
    3.         StartCoroutine( PlayAudioStrem() );
    4.     }
    5.  
    6.     IEnumerator PlayAudioStrem()
    7.     {
    8.         WWW music = new WWW(URL);
    9.         AudioClip clip = music.GetAudioClip(false, true, AudioType.MPEG);
    10.  
    11.         while (!clip || !clip.isReadyToPlay)
    12.             yield return new WaitForSeconds(0.1f);
    13.        
    14.         if (clip)
    15.         {
    16.             GetComponent<AudioSource>().clip = clip;
    17.             GetComponent<AudioSource>().Play();
    18.         }
    19.     }
    And it's actually plays... for 2 seconds! And then stops. Why it doesn't work?
    Please help!
     
  4. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,302
    don't post in the thread with different issue - ask the question in a new one
    that said - I don't know - you seem to be using rather old version of unity and I know it had problems emulating e.g. mpeg on desktop for example
    I think the code misses some yielding of www to properly stream the connection ( I think in your case it just plays what it can retrieve from initial connection )
     
  5. Lampogolovii_

    Lampogolovii_

    Joined:
    Aug 28, 2017
    Posts:
    12
    r618, thanks.
    I've created the new one.

    I'm looking for the working method (Unity2017), don't know which solution works fine. Please help.