From 4836e4c4c07a9b681ef0f0c43a0ab0254639dc4c Mon Sep 17 00:00:00 2001 From: r0r-5chach Date: Sat, 19 Oct 2024 19:50:18 +0100 Subject: [PATCH] Microphone access and stream --- src/main/kotlin/Microphone.kt | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/main/kotlin/Microphone.kt diff --git a/src/main/kotlin/Microphone.kt b/src/main/kotlin/Microphone.kt new file mode 100644 index 0000000..9f86878 --- /dev/null +++ b/src/main/kotlin/Microphone.kt @@ -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 + } +} \ No newline at end of file