-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
36 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
ronebot-silk-codec-ext/src/main/kotlin/cn/rtast/rob/silk/SilkDecoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright © 2024 RTAkland | ||
* Author: RTAkland | ||
* Date: 2024/11/17 | ||
*/ | ||
|
||
@file:Suppress("unused") | ||
|
||
package cn.rtast.rob.silk | ||
|
||
import io.github.kasukusakura.silkcodec.SilkCoder | ||
import java.io.ByteArrayOutputStream | ||
import java.io.File | ||
import java.io.InputStream | ||
|
||
/** | ||
* 从一个[InputStream]转换成PCM格式的音频, 但是需要参数传入 | ||
*/ | ||
fun InputStream.decodeToSilk(sampleRate: Int, strict: Boolean, loss: Int): ByteArray { | ||
val outputStream = ByteArrayOutputStream() | ||
SilkCoder.decode(this, outputStream, strict, sampleRate, loss) | ||
return outputStream.toByteArray() | ||
} | ||
|
||
/** | ||
* 从一个[File]转换成PCM格式的音频, 但是需要参数传入 | ||
*/ | ||
fun File.decodeToSilk(sampleRate: Int, strict: Boolean, loss: Int): ByteArray { | ||
val outputStream = ByteArrayOutputStream() | ||
SilkCoder.decode(this.inputStream(), outputStream, strict, sampleRate, loss) | ||
return outputStream.toByteArray() | ||
} | ||
|
||
/** | ||
* 从一个[InputStream]转换成PCM格式的音频 | ||
*/ | ||
fun InputStream.decodeToSilk(): ByteArray { | ||
val outputStream = ByteArrayOutputStream() | ||
SilkCoder.decode(this, outputStream) | ||
return outputStream.toByteArray() | ||
} | ||
|
||
/** | ||
* 从一个[File]对象转换成PCM格式的音频 | ||
*/ | ||
fun File.decodeToSilk(): ByteArray { | ||
val outputStream = ByteArrayOutputStream() | ||
SilkCoder.decode(this.inputStream(), outputStream) | ||
return outputStream.toByteArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters