2016-03-20 8 views
1

ユーザーの声を録音しているボイスエフェクトで再生できるiOSアプリケーションを作成していますが、問題は、内蔵のiPhoneマイクを使用しているときに再生が非常に静かなことです。ヘッドフォンは問題ありません。AVAudioEngine低音量

録音コード:

let recordingName = "my_audio.m4a" 
let pathArray = [dirPath, recordingName] 
let filePath = NSURL.fileURLWithPathComponents(pathArray) 
print(filePath) 

let recordSettings: [String: AnyObject] = [ 
    AVFormatIDKey: Int(kAudioFormatAppleLossless), 
    AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue, 
    AVEncoderBitRateKey : 320000, 
    AVNumberOfChannelsKey: 2, 
    AVSampleRateKey : 44100.0 
] 

let session = AVAudioSession.sharedInstance() 
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord) 
try! audioRecorder = AVAudioRecorder(URL: filePath!, settings: recordSettings) 

audioRecorder.meteringEnabled = true 
audioRecorder.updateMeters() 
audioRecorder.delegate = self 
audioRecorder.prepareToRecord() 
audioRecorder.record() 

再生コード:

playerNode.stop() 
playerNode.volume = 1.0 
audioEngine.stop() 
audioEngine.reset() 

audioEngine.attachNode(playerNode) 
audioEngine.attachNode(audioUnitTime) 
audioEngine.connect(playerNode, to: audioUnitTime, format: receivedAudio.processingFormat) 
audioEngine.connect(audioUnitTime, to: audioEngine.outputNode, format: receivedAudio.processingFormat) 

playerNode.scheduleFile(receivedAudio, atTime: nil, completionHandler: nil) 
try! audioEngine.start() 
playerNode.play() 

私のためのソリューションの唯一の痕跡は、元アップルの音声録音アプリは同じですが、ときにのみ、右上隅のスピーカーをしていることですアイコンが無効になります。私はそのスピーカーのアイコンが何であるかを知ることができませんでした。

答えて

2

私はそれを最後に見つけました。問題はAVAudioSessionで発生しました。

let session = AVAudioSession.sharedInstance() 
try! session.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions:AVAudioSessionCategoryOptions.DefaultToSpeaker) 
+0

サンプルを試しています。私がマイクを介して私のスピーチを認識し始めた場合、私はその認識されたテキストのiPhoneの音声を取得しようとしました。それは働いている。しかし、声は低すぎます。これで私を導くことができますか? –

+0

https://stackoverflow.com/questions/45371931/swift-iphones-volume-is-low-when-trying-to-change-speech-to-iphones-voice-in 私の質問.... –

関連する問題