my IEnumerator does not work.

I have a script that plays an audio file. I want it to play the same sound 10 times with a 3 second period between them (the audio is 2 seconds long).
But I cant get the Ienumerator to work at all.

using UnityEngine;
using System.Collections;

public class RobotTalks : MonoBehaviour 
{
    public AudioClip Help1;
	
    public void talk(bool n)
    {
        for(int i=0; i<10; i++)
        {
            Debug.Log("now i speak"+n + "  "+i);
            audio.PlayOneShot(Help1);	

            StartCoroutine(WaitASec(5.0F)); // Problem is here
			
            audio.PlayOneShot(Help1);	
        }
		
    }

    IEnumerator WaitASec(float waitTime){
       yield return new WaitForSeconds(waitTime);
    }		
}

the function talk is trigererd with .sendmessage from another script.
I now it works cause is the debug.log “now i speakTrue 0” … “now i speakTrue 9”
only thing is it happens instantly and i gont get 5 sec delay between debug messages and i only hear the sound once which is probably played instantly 10 times.

any ideas?

(Edit by Berenger : formattage and left only relevant code. Full code)

StartCoroutine does only what its name suggests: it starts the coroutine, but doesn’t wait its completion to return - it returns in the first yield.

In order to wait the interval, talk should be a coroutine:

public IEnumerator talk(bool n){
  if(n==true){
    for(int i=0; i<10; i++)
    {
       //Randomtime=Random.Range(1,10);
       Debug.Log("now i speak"+n + "  "+i);
       audio.PlayOneShot(Help1); 
       yield return new WaitForSeconds(5.0F);
    }
  }
}

Make sure that talk isn’t called before the last talk coroutine has finished, or you will get two or more coroutines running in parallel and crying Help1 at their own timings! You can start the coroutine at Start (if it will not be started again) or use a boolean flag to avoid starting a new coroutine while the previous is still running:

bool running = false;

public IEnumerator talk(bool n){
  if(running==false && n==true){ // do nothing if some talk instance is running
    running = true; // signals that talk is running
    for(int i=0; i<10; i++)
    {
       //Randomtime=Random.Range(1,10);
       Debug.Log("now i speak"+n + "  "+i);
       audio.PlayOneShot(Help1); 
       yield return new WaitForSeconds(5.0F);
    }
    running = false; // coroutine ended
  }
}