Created
July 11, 2018 02:00
-
-
Save hansemannn/1414ea2d11238d1ce99d0528cc4d0cc7 to your computer and use it in GitHub Desktop.
Microphone monitoring in Appcelerator Titanium using the AVAudioRecorder API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var ButtonTitle = { | |
START: 'Start Microphone Monitoring', | |
STOP: 'Stop Microphone Monitoring' | |
}; | |
Object.freeze(ButtonTitle); | |
var started = false; | |
var interval = null; | |
var win = Ti.UI.createWindow({ | |
backgroundColor: '#fff' | |
}); | |
var btn = Ti.UI.createButton({ | |
title: ButtonTitle.START | |
}); | |
btn.addEventListener('click', function buttonHandler() { | |
if (!started) { | |
Ti.Media.startMicrophoneMonitor(); | |
interval = setInterval(microphoneInterval, 1000); | |
started = true; | |
btn.title = ButtonTitle.STOP; | |
} else { | |
Ti.Media.stopMicrophoneMonitor(); | |
clearInterval(interval); | |
started = false; | |
btn.title = ButtonTitle.START; | |
} | |
}); | |
function microphoneInterval() { | |
Ti.API.info('Average mic-power: ' + Ti.Media.averageMicrophonePower); | |
Ti.API.info('Peak mic-power: ' + Ti.Media.peakMicrophonePower); | |
} | |
win.add(btn); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment