Skip to content

Commit 58d53e5

Browse files
committed
Support for voice optimised codecs
Support for voice optimised codecs
1 parent 8582db3 commit 58d53e5

File tree

6 files changed

+100
-12
lines changed

6 files changed

+100
-12
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77
#### **ConvertIt** is an ad free audio/video converter and metadata editor app built using kotlin & compose and powered by ffmpeg and taglib
88

9+
<<<<<<< Updated upstream
910

1011
#### Features
1112
- **Multiple Formats** : **FLAC, MP3, WAV, AAC, OGG, M4A, AIFF, OPUS, WMA, MKA, SPX**, and more.
1213
- **Bitrate Options** : Choose from bitrates such as **64k, 96k, 128k, 192k, 256k, 320k, 512k, 768k, and 1024k** for output quality.
14+
=======
15+
## Features
16+
- **Multiple Formats** : **FLAC, MP3, WAV, AAC, OGG, M4A, AIFF, OPUS, WMA, MKA, SPX, AMR WB**, and more.
17+
- **Bitrate Options** : Choose from bitrates such as **9k, 16k, 24k, 32k, 48k, 64k, 96k, 128k, 192k, 256k, 320k, 512k, 768k, and 1024k** for output quality.
18+
>>>>>>> Stashed changes
1319
- **Modern Design** : Uses MaterialYou(aka Material3).
1420
- **Ad-Free** : Completely free and no annoying Ads.
1521
- **User-Friendly-UI** : The UI and Conversion flow is so simple that everyone can figure out with nearly zero effort.

app/src/main/java/com/nasahacker/convertit/data/repository/AudioConverterRepositoryImpl.kt

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,16 @@ class AudioConverterRepositoryImpl
134134

135135
val mediaDuration = getAudioDuration(tempFile.absolutePath)
136136

137+
val ffmpegArgs = buildFFmpegArgs(
138+
tempFile.absolutePath,
139+
outputFilePath,
140+
outputFormat,
141+
bitrate,
142+
playbackSpeed
143+
)
144+
137145
FFmpegKit.executeWithArgumentsAsync(
138-
arrayOf(
139-
"-y",
140-
"-i",
141-
tempFile.absolutePath,
142-
"-c:a",
143-
AudioCodec.fromFormat(outputFormat).codec,
144-
"-b:a",
145-
bitrate.bitrate,
146-
"-filter:a",
147-
"atempo=$playbackSpeed",
148-
outputFilePath,
149-
),
146+
ffmpegArgs,
150147
{ session ->
151148
tempFile.delete()
152149

@@ -195,6 +192,64 @@ class AudioConverterRepositoryImpl
195192
}
196193
}
197194

195+
private fun buildFFmpegArgs(
196+
inputPath: String,
197+
outputPath: String,
198+
outputFormat: AudioFormat,
199+
bitrate: AudioBitrate,
200+
playbackSpeed: String
201+
): Array<String> {
202+
Log.d(TAG, "Building FFmpeg args for format: ${outputFormat.extension}, bitrate: ${bitrate.bitrate}")
203+
return when (outputFormat) {
204+
AudioFormat.AMR_WB -> {
205+
arrayOf(
206+
"-y",
207+
"-i", inputPath,
208+
"-ar", "16000",
209+
"-ac", "1",
210+
"-c:a", AudioCodec.fromFormat(outputFormat).codec,
211+
"-b:a", bitrate.bitrate,
212+
"-filter:a", "atempo=$playbackSpeed",
213+
outputPath
214+
)
215+
}
216+
AudioFormat.OPUS -> {
217+
218+
if (bitrate.bitrate.replace("k", "").toIntOrNull()?.let { it <= 48 } == true) {
219+
arrayOf(
220+
"-y",
221+
"-i", inputPath,
222+
"-c:a", AudioCodec.fromFormat(outputFormat).codec,
223+
"-b:a", bitrate.bitrate,
224+
"-application", "voip",
225+
"-filter:a", "atempo=$playbackSpeed",
226+
outputPath
227+
)
228+
} else {
229+
230+
arrayOf(
231+
"-y",
232+
"-i", inputPath,
233+
"-c:a", AudioCodec.fromFormat(outputFormat).codec,
234+
"-b:a", bitrate.bitrate,
235+
"-filter:a", "atempo=$playbackSpeed",
236+
outputPath
237+
)
238+
}
239+
}
240+
else -> {
241+
arrayOf(
242+
"-y",
243+
"-i", inputPath,
244+
"-c:a", AudioCodec.fromFormat(outputFormat).codec,
245+
"-b:a", bitrate.bitrate,
246+
"-filter:a", "atempo=$playbackSpeed",
247+
outputPath
248+
)
249+
}
250+
}
251+
}
252+
198253
private fun getAudioDuration(filePath: String): Long =
199254
try {
200255
val session = FFprobeKit.getMediaInformation(filePath)

app/src/main/java/com/nasahacker/convertit/domain/model/AudioBitrate.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ package com.nasahacker.convertit.domain.model
3030
enum class AudioBitrate(
3131
val bitrate: String,
3232
) {
33+
// voice optimized ones
34+
BITRATE_9K("9k"),
35+
BITRATE_16K("16k"),
36+
BITRATE_24K("24k"),
37+
BITRATE_32K("32k"),
38+
BITRATE_48K("48k"),
39+
40+
// other standard
3341
BITRATE_64K("64k"),
3442
BITRATE_96K("96k"),
3543
BITRATE_128K("128k"),

app/src/main/java/com/nasahacker/convertit/domain/model/AudioCodec.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum class AudioCodec(
4141
WMA("wmav2"),
4242
MKA("libvorbis"),
4343
SPX("libspeex"),
44+
AMR_WB("amr_wb"),
4445
;
4546

4647
companion object {
@@ -57,6 +58,7 @@ enum class AudioCodec(
5758
AudioFormat.MKA -> MKA
5859
AudioFormat.SPX -> SPX
5960
AudioFormat.FLAC -> FLAC
61+
AudioFormat.AMR_WB -> AMR_WB
6062
}
6163
}
6264
}

app/src/main/java/com/nasahacker/convertit/domain/model/AudioFormat.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ enum class AudioFormat(
4141
WMA(".wma"),
4242
MKA(".mka"),
4343
SPX(".spx"),
44+
AMR_WB(".amr"),
4445
;
4546

4647
companion object {

app/src/main/res/values/arrays.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string-array name="bitrates_array">
4+
<item>9k</item>
5+
<item>16k</item>
6+
<item>24k</item>
7+
<item>32k</item>
8+
<item>48k</item>
49
<item>64k</item>
510
<item>96k</item>
611
<item>128k</item>
@@ -21,6 +26,7 @@
2126
<item>.wma</item>
2227
<item>.mka</item>
2328
<item>.spx</item>
29+
<item>.amr</item>
2430
</string-array>
2531

2632

@@ -63,6 +69,10 @@
6369
</string-array>
6470

6571
<string-array name="bitrates_opus">
72+
<item>16k</item>
73+
<item>24k</item>
74+
<item>32k</item>
75+
<item>48k</item>
6676
<item>64k</item>
6777
<item>96k</item>
6878
<item>128k</item>
@@ -99,4 +109,10 @@
99109
<item>192k</item>
100110
</string-array>
101111

112+
<string-array name="bitrates_amr">
113+
<item>9k</item>
114+
<item>16k</item>
115+
<item>24k</item>
116+
</string-array>
117+
102118
</resources>

0 commit comments

Comments
 (0)