【问题标题】:Can we use AVAudiorecorder in swift playgrounds?我们可以在 Swift Playground 中使用 AVAudiorecorder 吗?
【发布时间】:2017-01-18 12:50:19
【问题描述】:

在将代码放入我的应用程序之前,我正在尝试在 Playground 中对代码进行原型设计。我们可以使用 swift Playground 录制音频吗?

非常感谢,

费拉斯 A.

以下是我目前的尝试,但 audioFile 没有任何长度、属性或数据:-

import UIKit
import AVFoundation

var soundRecorder: AVAudioRecorder!
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let OutputFilePath = documentsDirectory.appendingPathComponent("out.wav")

//set the settings for recorder
var recordSettings = [
    AVFormatIDKey: kAudioFormatAppleLossless,
    AVEncoderAudioQualityKey : AVAudioQuality.max.rawValue,
    AVEncoderBitRateKey : 320000,
    AVNumberOfChannelsKey: 2,
    AVSampleRateKey : 44100.0
] as [String : Any]

try soundRecorder = AVAudioRecorder(url: OutputFilePath, settings: recordSettings)
soundRecorder.record(forDuration: 10)
let audioFile = try AVAudioFile(forReading: OutputFilePath)

【问题讨论】:

  • 你用谷歌搜索过吗?
  • 或者你有没有尝试过任何东西
  • Paul - 是的,没有原生的 swift 答案,audioKit 可以。
  • 好吧,这是一个改进。如果您描述了这是如何行不通的,我可能会想撤销我的反对票。
  • @FerasAS 如何在操场上录制音频。即使你不能在模拟器中做到这一点。你需要真实的设备。

标签: ios swift avaudiorecorder


【解决方案1】:

我认为这是不可能的。由于没有设备可以录制音频,但我认为您可以连接外部设备并将其用作模拟器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2020-03-21
    • 2011-08-21
    相关资源
    最近更新 更多