Tag: avaudioplayer

录制audio时如何将audio录制设置更改为16Khz和16位?

我有下面的设置。 录制audio时,我想将audio录制设置更改为16Khz和16位。 NSArray *dirPaths; NSString *docsDir; dirPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.wav"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt:16], AVEncoderBitRateKey, [NSNumber numberWithInt: 2], AVNumberOfChannelsKey, [NSNumber numberWithFloat:44100.0], AVSampleRateKey, nil]; NSError *error = nil; audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings […]

如何录制video并同时播放audio(快速教程)

那么您想要录制video并同时播放用户库中的 音乐吗? 再看一眼。 以下是答案。

iPhone SDK:从一个button播放一个WAV

我目前正在尝试这个代码: NSString *path = [[NSBundle mainBundle] pathForResource:@"dream" ofType:@"m4a"]; AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; theAudio.delegate = self; [theAudio play]; 但是,SDK说ViewController没有实现AVAudioPlayer委托。 任何机构有关如何使用2.2 SDK播放WAV(或M4a)的任何想法?

我可以在AppDelegate上使用AVAudioPlayer吗?

我有一个TabBarController与两个选项卡,我想在两个选项卡上播放音乐。 现在我有我的代码在主appDelegate NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"My Song" ofType:@"m4a"]]; // My Song.m4a NSError *error; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; if (error) { NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); } else { //audioPlayer.delegate = self; [audioPlayer prepareToPlay]; } 但我得到错误Program received signal: "SIGABRT" UIApplicationMain上的Program received signal: "SIGABRT" 有没有更好的方法来完成我想要做的事情? 如果这是我应该怎么做的,我该从哪里开始检查问题?

MPMediaItem不使用MPMediaItemPropertyAssetURL在AVAudioPlayer中播放

我有这个代码,find并播放MPMediaItem: MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:self.persistentIDOfSongToPlay forProperty:MPMediaItemPropertyPersistentID comparisonType:MPMediaPredicateComparisonContains]; NSSet *predicateSet = [NSSet setWithObject:predicate]; MPMediaQuery *searchQuery = [[MPMediaQuery alloc] initWithFilterPredicates:predicateSet]; NSArray *queryResults = [searchQuery items]; NSLog(@"count: %i", queryResults.count); MPMediaItem *item = [queryResults objectAtIndex:0]; NSLog(@"item: %@", item); NSURL *itemURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; NSLog(@"url: %@", itemURL); NSError *error; AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:itemURL error:&error]; [audioPlayer prepareToPlay]; [audioPlayer […]

使用AVAudioPlayer时OSStatus错误2003334207

我试图播放MP3文件(当通过VLC / iTunes播放时)按下button时。 这是我的代码: var audioPlayer: AVAudioPlayer! @IBAction func playEpisode(sender: AnyObject) { println("now playing") let indexPath = NSIndexPath(forRow: sender.tag, inSection: 0) let data: CDEpisode = fetchedResultsController.objectAtIndexPath(indexPath!) as! CDEpisode var err: NSError? let url = NSURL(string: data.localPath) println("The url is \(url)") audioPlayer = AVAudioPlayer(contentsOfURL: url, error: &err) if audioPlayer == nil { if let e = […]

AVAudioSession Swift

我正在写一个快速的iOS应用程序,将logging用户的声音。 我在swift中编写了下面的代码,但它无法从用户请求话筒权限。 它打印的授权,但它从来没有loggingaudio,并在隐私设置窗格中不列出的应用程序。 如何在swift中请求录制权限? var session: AVAudioSession = AVAudioSession.sharedInstance() session.requestRecordPermission({(granted: Bool)-> Void in if granted { println(" granted") session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil) session.setActive(true, error: nil) self.recorder.record() }else{ println("not granted") } })

如何告诉MPNowPlayingInfoCenter是否正在播放或暂停音乐?

我似乎无法让iOS在远程audio控件中显示正确的播放/暂停button。 我收到远程控制事件并设置nowPlayingInfo字典的所有值。 一切工作正常,我甚至看到锁屏上的封面照片。 除了暂停/播放button。 即使我的AVAudioPlayer正在播放,它总是看起来像暂停。 无论播放状态如何,它都会发送一个暂停事件。 如何通知iOS AVAudioPlayer已暂停,现在应该在遥控器button栏中显示播放button?

为什么我暂停AVAudioPlayer时锁屏audio控制消失?

我正在使用AVAudioPlayer的实例来播放audio文件。 该应用程序被configuration为在后台播放audio,并设置适当的audio会话。 我也成功接收远程控制事件。 代码如下: #import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewController () @property (nonatomic) AVAudioPlayer *player; @end @implementation ViewController @synthesize player; – (BOOL)canBecomeFirstResponder { return YES; } – (void)viewDidLoad { [super viewDidLoad]; // Turn on remote control event delivery [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; // Set ourselves as the first responder [self becomeFirstResponder]; // Set the audio session […]

Swift:试图迅速改变语音到iPhone的声音时,iPhone的音量很低

我正在尝试语音识别示例。 如果我开始通过麦克风来识别我的发言,那么我试图让iPhone识别文本的声音。 这是工作。 但是,声音太低了。 你能指导我吗? 而不是,如果我正在尝试简单的button操作,与AVSpeechUtterance代码,音量是正常的。 之后,如果我使用startRecognise()方法,则音量太低。 我的代码 func startRecognise() { let audioSession = AVAudioSession.sharedInstance() //2 do { try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) try audioSession.setMode(AVAudioSessionModeDefault) try audioSession.setMode(AVAudioSessionModeMeasurement) try audioSession.setActive(true, with: .notifyOthersOnDeactivation) try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.speaker) } catch { print("audioSession properties weren't set because of an error.") } recognitionRequest = SFSpeechAudioBufferRecognitionRequest() guard let inputNode = audioEngine.inputNode else { fatalError("Audio engine has […]