访问 Apple Watch 的麦克风 [英] Access Apple Watch's microphone
本文介绍了访问 Apple Watch 的麦克风的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在关于 Apple Watch 的文档越来越多,有没有人找到访问和使用设备麦克风的方法?
Now that more and more documentation on the Apple Watch is surfacing has anybody found a way to access and use the device's microphone?
推荐答案
您可以在 watchOS 2 上访问 Watch 的麦克风.
You can access the Watch's microphone on watchOS 2.
1) 创建一个文件 URL,用于存储记录的输出.
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,YES);
NSString *path = [[filePaths firstObject] stringByAppendingPathComponent:@"rec.m4a"];
NSURL *fileUrl = [NSURL fileURLWithPath:path];
您可以指定扩展名 .wav、.mp4 和 .m4a.
You may specify the extensions .wav, .mp4, and .m4a.
2) 调用方法如下:
[self presentAudioRecordingControllerWithOutputURL:fileUrl
preset:WKAudioRecordingPresetWideBandSpeech
maximumDuration:5.0
actionTitle:@"Some Title"
completion:^(BOOL didSave, NSError * __nullable error) {
NSLog(@"didSave:%d, error:%@", didSave, error);
}];
除了上述之外,您还可以选择预设
You can choose preset in addition to the above
- WKAudioRecordingPresetNarrowBandSpeech
- WKAudioRecordingPresetHighQualityAudio
在 Swift 中:
self.presentAudioRecordingControllerWithOutputURL(
self.recFileURL(),
preset: WKAudioRecordingPreset.WideBandSpeech,
maximumDuration: 5.0,
actionTitle: "SomeTitle") { (didSave, error) -> Void in
print("didSave:\(didSave), error:\(error)")
}
您可以按如下方式播放录制的文件:
You can play the recorded file as follows:
self.presentMediaPlayerControllerWithURL(
fileURL,
options: nil) { (didPlayToEnd, endTime, error) -> Void in
print("didPlayToEnd:\(didPlayToEnd), endTime:\(endTime), error:\(error)")
}
您可以查看详细规范此处.
这篇关于访问 Apple Watch 的麦克风的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文