File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
examples/whisper.android/app/src/main/java/com/whispercppdemo/media Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,16 @@ fun decodeWaveFile(file: File): FloatArray {
10
10
file.inputStream().use { it.copyTo(baos) }
11
11
val buffer = ByteBuffer .wrap(baos.toByteArray())
12
12
buffer.order(ByteOrder .LITTLE_ENDIAN )
13
+ val channel = buffer.getShort(22 ).toInt()
13
14
buffer.position(44 )
14
15
val shortBuffer = buffer.asShortBuffer()
15
16
val shortArray = ShortArray (shortBuffer.limit())
16
17
shortBuffer.get(shortArray)
17
- return FloatArray (shortArray.size) { index ->
18
- (shortArray[index] / 32767.0f ).coerceIn(- 1f .. 1f )
18
+ return FloatArray (shortArray.size / channel) { index ->
19
+ when (channel) {
20
+ 1 -> (shortArray[index] / 32767.0f ).coerceIn(- 1f .. 1f )
21
+ else -> ((shortArray[2 * index] + shortArray[2 * index + 1 ])/ 32767.0f / 2.0f ).coerceIn(- 1f .. 1f )
22
+ }
19
23
}
20
24
}
21
25
@@ -73,4 +77,4 @@ private fun headerBytes(totalLength: Int): ByteArray {
73
77
it.get(bytes)
74
78
return bytes
75
79
}
76
- }
80
+ }
You can’t perform that action at this time.
0 commit comments