mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
feat: Add concatenate functionality
This commit is contained in:
parent
f79315e0c3
commit
7b19be595c
@ -71,5 +71,7 @@ dependencies {
|
||||
annotationProcessor 'com.google.dagger:hilt-compiler:2.46.1'
|
||||
implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
|
||||
|
||||
implementation 'com.arthenica:ffmpeg-kit-full:5.1'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
||||
}
|
@ -79,24 +79,19 @@ fun AudioRecorder() {
|
||||
Text(text = if (isRecording) "Stop" else "Start")
|
||||
}
|
||||
if (!isRecording && service != null)
|
||||
LazyColumn() {
|
||||
val items = service!!.getRecordingFilePaths().toList()
|
||||
Button(
|
||||
onClick = {
|
||||
val path = service!!.concatenateAudios()
|
||||
|
||||
items(items.size) {
|
||||
val path = items[it]
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
val player = MediaPlayer().apply {
|
||||
setDataSource(path)
|
||||
prepare()
|
||||
start()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(text = "Play $it")
|
||||
val player = MediaPlayer().apply {
|
||||
setDataSource(path)
|
||||
prepare()
|
||||
}
|
||||
}
|
||||
|
||||
player.start()
|
||||
},
|
||||
) {
|
||||
Text(text = "Convert")
|
||||
}
|
||||
}
|
||||
}
|
@ -9,8 +9,11 @@ import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.IBinder
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
import com.arthenica.ffmpegkit.ReturnCode
|
||||
import kotlinx.coroutines.NonCancellable.start
|
||||
import java.io.File
|
||||
import java.time.LocalDateTime
|
||||
@ -19,7 +22,7 @@ import java.util.Date
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
const val INTERVAL_DURATION = 30000L
|
||||
const val INTERVAL_DURATION = 10000L
|
||||
|
||||
class RecorderService: Service() {
|
||||
private val binder = LocalBinder()
|
||||
@ -74,6 +77,30 @@ class RecorderService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
fun concatenateAudios(): String {
|
||||
val paths = getRecordingFilePaths().joinToString("|")
|
||||
val outputFile = "$fileFolder/concatenated.${getFileExtensions()}"
|
||||
val command = "-i \"concat:$paths\" -acodec copy $outputFile"
|
||||
|
||||
val session = FFmpegKit.execute(command)
|
||||
|
||||
if (!ReturnCode.isSuccess(session.returnCode)) {
|
||||
Log.d(
|
||||
"Audio Concatenation",
|
||||
String.format(
|
||||
"Command failed with state %s and rc %s.%s",
|
||||
session.getState(),
|
||||
session.getReturnCode(),
|
||||
session.getFailStackTrace()
|
||||
)
|
||||
);
|
||||
|
||||
throw Exception("Failed to concatenate audios")
|
||||
}
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
private fun startNewRecording() {
|
||||
if (!isRecording) {
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user