Search code examples
iosobjective-cswift3media-playeravaudioplayer

How to play array of words or NSString using AVAudioPlayer?


I have Array of words which i want to pick one after the other and play using AVAudioPlayer, how can i achieve playing NSString using AVAudioPlayer?

I don't have the audio file and i have list of words to which i want to play each word using AVAudioPlayer programming .

i found to play the audio file using AVAudioPlayer but not able to find to play NSSting or word in AVAudioPlayer

Below is the code using to play the audio clips :

NSString *path = [NSString stringWithFormat:@"%@/audio.mp3", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];

Solution

  • You need to create an AVSpeechUtterance object using the words that you want the device to "speak," and then pass that object to AVSpeechSynthesizer. Those classes provide the methods you need to control the speech; there's no need to use AVAudioPlayer.