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];
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.
Related
i am trying to make an online audio player. but i can't paly audio using AVAudioPlayer object. Please Help Me. Thanks in Advance.
Here is my audio player code.
================>>
NSURL *url =[[NSURL alloc] initWithString:#"My Url"];
xPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
xPlayer.numberOfLoops = 0;
xPlayer.volume = 1.0f;
[xPlayer prepareToPlay];
[xPlayer play];
Q: Does the AVAudioPlayer provide support for streaming audio content?
A: The AVAudioPlayer class does not provide support for streaming audio based on HTTP URL's. The URL used with initWithContentsOfURL: must be a File URL (file://). That is, a local path.
Source: https://developer.apple.com/library/ios/qa/qa1634/_index.html
Is is possible to play built-in sounds with AVAudioPlayer, to get around the limitations of AudioServicesPlaySystemSound?
For example:
AudioServicesPlaySystemSound(1360);
vs.
AVAudioPlayer
NSURL* url = [[NSBundle mainBundle] URLForResource:#"???" withExtension:#"??"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
[player play];
What would the path or code be (if possible)?
I want to play a radio station when someone presses the play radio button. However, it does not work.
Here is my code:
NSURL *url = [NSURL URLWithString:#"http://www.radio.net.pk/"];
NSData *data = [NSData dataWithContentsOfURL:url];
AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithData:data error:nil];
[audio play];
The AVAudioPlayer class only lets you play sound in any audio format available in iOS and OS X
This means, the AVAudioPlayer class does not provide support for streaming audio based on HTTP URL's. The URL used with initWithContentsOfURL: must be a local path URL.
So you should save the NSData locally (with different chunks) and play it using AVAudioPlayer.
It won't work ever.
Does radio.net.pk offers any APIs?
datWithContentsOfURL will return HTML string that you are trying to play using AVAudioPlayer !!. Please go through the website again and check for any developer API.
// Using this Cannel
NSURL *url6 = [NSURL URLWithString:#"http://sc6.spacialnet.com:35464/"]
layerItem = [AVPlayerItem playerItemWithURL:_strTemp]; // add url to playerItem
player = [AVPlayer playerWithPlayerItem:playerItem]; // add player item to AVAudioPlayer
player = [AVPlayer playerWithURL:_strTemp]
I have the following code that used to work to play a sound in my project however after iv done some playing around over the past few weeks on other aspects of the project it dose not seem to play.
The audio file is in the main directory and works in preview.
Any ideas?
//playsound
AVAudioPlayer *showsound;
NSString *audiopath = [[NSBundle mainBundle] pathForResource:#"mouse1" ofType:#"wav"];
NSURL *audiourl = [NSURL fileURLWithPath:audiopath];
showsound = [[AVAudioPlayer alloc]initWithContentsOfURL:audiourl error:Nil];
[showsound play];
It's because after the line showsound play your method comes to an end and showsound (your AVAudioPlayer) is released. Hence there is nothing to do any playing any more. Solution: retain it! (For example, set an instance variable to hold on to it.)
I am using the following code to get a sound on button click.And it works perfect. The problem is this sound is not getting reduced if i reduce the volume on the phone. I want to manage button click sound as per the volume button. I am not using input view.
SystemSoundID soundID;
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"sound1" ofType:#"mp3"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath];
AudioServicesCreateSystemSoundID ((CFURLRef) CFBridgingRetain(soundUrl) , &soundID);
AudioServicesPlaySystemSound(soundID);
As Duncan C suggests, try AVAudioPlayer:
Import AVFoundation.framework.
Replace your code snippet with:
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"sound1" ofType:#"mp3"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
[player play];
What I do is to create an AVAudioPlayer for my button sound and play that. AVAudioPlayer honors the system volume.
I've created a separate IBAction method that plays the sound, and then I link my buttons to both actions. That way it's easy to turn the sound on and off simply by linking the action. If you always want sounds to play then you might want to put a call to a sound play method directly in your IBAction methods.
Check Click here that might help you.