Microphone access and stream
This commit is contained in:
parent
59cad38f74
commit
4836e4c4c0
|
|
@ -0,0 +1,61 @@
|
|||
import javax.sound.sampled.AudioFormat
|
||||
import javax.sound.sampled.AudioSystem
|
||||
import javax.sound.sampled.DataLine
|
||||
import javax.sound.sampled.TargetDataLine
|
||||
/**
|
||||
* TODO: Documentation
|
||||
*/
|
||||
class Microphone {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private val source = getSource()
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private val audioFormat = getFormat()
|
||||
/**
|
||||
*
|
||||
*/
|
||||
fun startCapture() {
|
||||
source.start()
|
||||
//TODO: Start processing loop in new coroutine and check if it could be moved into own file
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
fun stopCapture() {
|
||||
source.stop()
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
fun closeSource() {
|
||||
source.close()
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private fun getFormat(): AudioFormat {
|
||||
return AudioFormat( //TODO: Get format settings from user settings
|
||||
16000.0f, // 16000 Required
|
||||
16,
|
||||
2,
|
||||
true,
|
||||
true
|
||||
)
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private fun getSource(): TargetDataLine {
|
||||
val info = DataLine.Info(
|
||||
TargetDataLine::class.java,
|
||||
audioFormat
|
||||
)
|
||||
val source = AudioSystem.getLine(info) as TargetDataLine
|
||||
source.open(audioFormat)
|
||||
|
||||
return source
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue