简体   繁体   English

在iOS上实时录制,修改音高和播放音频

[英]Record, modify pitch and play back audio in real time on iOS

I just wondering if anyone can explain to me how I would go about recording audio, modifying it (pitch?) and playing it back to the user on iPhone. 我只是想知道是否有人可以向我解释如何录制音频,修改音频(音高?)并在iPhone上播放给用户。

I'm not asking for someone to do this for me, just a few hints on how I should go about it. 我不是要求有人为我做这件事,只是提示我应该怎么做。 looking through the docs it seems like I should be using AVAudioSession , AVAudioRecorder and AVAudioPlayer ( AVFoundation.Framework ) for the recording playing parts. 通过文档查看我似乎应该使用AVAudioSessionAVAudioRecorderAVAudioPlayerAVFoundation.Framework )来录制播放部分。 Or should I be using the CoreAudio.Framework ? 或者我应该使用CoreAudio.Framework and then there is the question regarding modifying the audio. 然后是关于修改音频的问题。

AVAudioUnitTimePitch should do the trick. AVAudioUnitTimePitch应该做的伎俩。

Sample code from udacity.com Intro to iOS App Development with Swift : 来自udacity.com的示例代码使用Swift进行iOS应用程序开发的简介

func playAudioWithVariablePitch(pitch: Float) {
    audioEngine.stop()
    audioEngine.reset()

    let audioPlayerNode = AVAudioPlayerNode()
    audioEngine.attachNode(audioPlayerNode)

    let changePitchEffect = AVAudioUnitTimePitch()
    changePitchEffect.pitch = pitch
    audioEngine.attachNode(changePitchEffect)

    audioEngine.connect(audioPlayerNode, to:changePitchEffect, format:nil)
    audioEngine.connect(changePitchEffect, to:audioEngine.outputNode, format:nil)

    audioPlayerNode.scheduleFile(audioFile, atTime:nil, completionHandler: nil)
    try! audioEngine.start()

    audioPlayerNode.play()
}

OpenAL is a library, that supports what you're searching for. OpenAL是一个库,支持您正在搜索的内容。 And its very popular on the iPhone, so maybe you should take a look on this. 它在iPhone上很受欢迎,所以也许你应该看看这个。 ie The pitch of an sample is easily changeable with only one command: 即只需一个命令即可轻松更改样本的音高:

alSourcef(source, AL_PITCH, pitch);

But I'm not sure, if pitch change is also with the AVFoundation or CoreAudio classes possible - never used them. 但是我不确定,如果音调改变也可以使用AVFoundation或CoreAudio类 - 从不使用它们。

This might help. 这可能有所帮助。 DIRAC-mobile , a library for real-time tempo and pitch manipulation of polyphonic audio signals. DIRAC-mobile ,一个用于复音音频信号的实时速度和音调操作的库。 They also have sample codes that you can take a look once you download the library. 它们还有示例代码,您可以在下载库后查看它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM