Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

ios - I want to record from iphone microphone and convert to ulaw format streaming

I want to record from iphone microphone and convert to ulaw format streaming data,I guess that is pcm data but I got noise.

What audio format is installTap buff? How can I do to got ulaw data format? I can got it from AVAudioRecorder but I'm not to got a file. Do change format settings 'AVFormatIDKey=kAudioFormatULaw' will got crash.

    func testMicrophoneRecording1 () throws {
        let tapNode: AVAudioNode = mixerNode
        let format = tapNode.outputFormat(forBus: 0)
       
        tapNode.installTap(onBus: 0, bufferSize: 1024, format: format, block: {
            (buffer, time) in
            let d = buffer.toNSData() as Data  
            let ulaw_data = convert_pcm_(to_ulaw: d) 
            sendUlawDataToDevice(data: ulaw_data)           
        })

        try engine.start()
    }

and connections is:

 func makeConnections() {
        let inputNode = engine.inputNode
        let inputFormat = inputNode.outputFormat(forBus: 0)
        engine.connect(inputNode, to: mixerNode, format: inputFormat)

        let mainMixerNode = engine.mainMixerNode
        let mixerFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: 44100, channels: 1, interleaved: true)
        engine.connect(mixerNode, to: mainMixerNode, format: mixerFormat)
    }
question from:https://stackoverflow.com/questions/66059910/i-want-to-record-from-iphone-microphone-and-convert-to-ulaw-format-streaming

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have got pcm from microphone and convert to ulaw,form this example: https://github.com/Epskampie/ios-coreaudio-example


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...