Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
xszqxszq committed Jan 20, 2024
1 parent 6c0d67d commit 1eabc7c
Show file tree
Hide file tree
Showing 254 changed files with 1,484 additions and 766 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ out/

### Bot Files ###
/maimai/covers/
/maimai/settings.yml
/config.yml
/src/test/
/music/
Binary file added audio/otto/ysddTokens/1.wav.reapeaks
Binary file not shown.
Binary file added audio/otto/ysddTokens/5.wav.reapeaks
Binary file not shown.
Binary file added audio/otto/ysddTokens/ah.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ahhhhh.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/amns.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/aq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/arjs.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/aydsl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/aymn.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/azwq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bbd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bjzs.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bp.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bsl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/by.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/byhj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/byl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bywx.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/byzg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bzd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/bzl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ce.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/cjbgj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/cnmkd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/cswyxd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ddbyl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dfg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dhdjbtmd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dnzkzmj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dsn.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dw.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dxqb.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dydzwwjjdnmblp.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dyn.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dyndyn.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dyndynjyxa.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/dynjyxa.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/fengmi.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/fm.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/gg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/gj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/gt.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/hgg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/hjm.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ht.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/htdr.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/htszljd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/huangjin.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/hz.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/jchz.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/jd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/jxs.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/jxsyg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/kda.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/kn.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/kns.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/kzzll.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/llk.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/llkla.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/lp.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/mbf.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ml.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/msmsl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nbyjdswdg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nczyx.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ngwshl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/njswdg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nltmxzsnnbsl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nltmxzsnnbslgsmwye.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nmblp.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nwqdzg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nwsmbsct.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/nzygr.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/oxg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/oxgoxg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/padoru.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/padorupadoru.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/qddbrdea.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/rjs.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/rq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/sb.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/sbqxbl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/sbqxbld.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/sdhyy.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/sgwba.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/sy.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tby.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tdyjzyl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tjd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tljl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/txsq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tyjd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/tysbq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wc.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wcsndm.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wdg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/whbrychtdd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wsmbq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wsmnzdm.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wsmxzhbq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wwsmhydxqn.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wyx.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/wzm.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/xcz.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ybmr.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yczbql.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ydw.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yghdhyb.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yinwei.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yq.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yqw.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yw.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ywbysdh.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/ywtljl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yyg.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/yyzykd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zb.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zbb.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zgdw.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zgfdszggd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zgyyzykd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zhdsgl.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zhydsj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zjyzdzj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zljd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/znhj.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zwsyd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zykd.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zzmzmc.wav
Binary file not shown.
Binary file added audio/otto/ysddTokens/zzmzmca.wav
Binary file not shown.
Binary file added chunithm/ui/CHU_UI_Common_batch_00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chunithm/ui/CHU_UI_Result_score_NUM_00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chunithm/ui/CHU_UI_Userbox_00_v11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chunithm/ui/CHU_UI_select_00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chunithm/ui/CHU_UI_title_rank_01_v10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_pages/meme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ permalink: /meme/

- 详细说明请点击[这里](/pjsk)查看
- 指令:`/pjsk 人物+编号 文本(支持多行)`
- **指令不用加`/生成`!!指令是`/pjsk`!!**
- 例:`/pjsk 初音6 纳尼`
- 预览:
<div align="left">
Expand Down
2 changes: 2 additions & 0 deletions docs/_pages/pjsk.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ permalink: /pjsk/

指令:`/pjsk 人物+编号 文本(支持多行)`

**指令不用加`/生成`!!指令是`/pjsk`!!**

- 例:`/pjsk 初音6 纳尼`
- 例:`/pjsk mzk14 气死我了`

Expand Down
3 changes: 2 additions & 1 deletion maimai/settings.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
theme: brief
zetarakuSite: "https://dp4p6x0xfi5o9.cloudfront.net"
xrayAliasUrl: "https://download.fanyu.site/maimai/alias.json"
xrayAliasUrl: "https://download.fanyu.site/maimai/alias.json"
lxnsSecret: "lvBN8aEfg1Dal0bSBupzNjAZ_pUAUcX2bGXmteirKGs="
94 changes: 65 additions & 29 deletions src/main/kotlin/xyz/xszq/KarenBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,29 @@ import korlibs.image.format.encode
import korlibs.image.format.readNativeImage
import korlibs.io.async.launch
import korlibs.io.file.std.localCurrentDirVfs
import korlibs.io.file.std.toVfs
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.withPermit
import nu.pattern.OpenCV
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.insert
import xyz.xszq.bot.dao.AccessLogs
import xyz.xszq.bot.audio.*
import xyz.xszq.bot.config.BinConfig
import xyz.xszq.bot.config.BotConfig
import xyz.xszq.bot.config.PJSKConfig
import xyz.xszq.bot.dao.*
import xyz.xszq.bot.ffmpeg.FFMpegTask
import xyz.xszq.bot.image.*
import xyz.xszq.bot.maimai.Maimai
import xyz.xszq.bot.maimai.QueueForArcades
import xyz.xszq.bot.text.*
import xyz.xszq.bot.rhythmgame.maimai.Maimai
import xyz.xszq.bot.rhythmgame.QueueForArcades
import xyz.xszq.bot.text.AutoQA
import xyz.xszq.bot.text.Bilibili
import xyz.xszq.bot.text.RandomText
import xyz.xszq.bot.text.WikiQuery
import xyz.xszq.nereides.*
import xyz.xszq.nereides.event.GlobalEventChannel
import xyz.xszq.nereides.event.GroupAtMessageEvent
import xyz.xszq.nereides.event.GuildAtMessageEvent
import xyz.xszq.nereides.event.*
import xyz.xszq.nereides.message.*
import xyz.xszq.nereides.message.ark.ListArk
import xyz.xszq.nereides.payload.message.MessageKeyboard
import kotlin.random.Random

lateinit var mariadb: Database
Expand Down Expand Up @@ -66,13 +63,11 @@ suspend fun init() {
QueueForArcades.init()
}

BuildImage.init()

RandomImage.load("reply")
RandomImage.load("gif", "reply")
RandomImage.load("afraid", "reply")

Maimai.initBlocking()
Maimai.init()
RandomText.loadSaizeriya()
}

Expand All @@ -84,17 +79,25 @@ fun subscribe() {
}
}
}
GlobalEventChannel.subscribe<BotJoinGroupEvent> {
launch(Dispatchers.IO) {
AccessLogs.saveLog(operator, groupId, "<joined>")
}
}
GlobalEventChannel.subscribe<BotLeaveGroupEvent> {
launch(Dispatchers.IO) {
AccessLogs.saveLog(operator, groupId, "<left>")
}
}
GlobalEventChannel.subscribePublicMessages {
startsWith("/ping") {
reply("bot在")
}
startsWith("/搜番") {
if (this is GroupAtMessageEvent) {
message.filterIsInstance<RemoteImage>().firstOrNull() ?.let { img ->
img.getFile().apply {
reply(AnimeDB.handle(this))
}.also {
it.delete()
img.use {
reply(AnimeDB.handle(it))
}
} ?: run {
reply("使用搜番命令时,请同时发送想要搜索的动漫截图!")
Expand Down Expand Up @@ -240,7 +243,7 @@ fun subscribe() {
file.cropPeriod(Random.nextDouble(
0.0,
file.getAudioDuration() - duration
), duration)?.let { v ->
), duration).useTempFile { v ->
reply(v.toVoice())
}
}
Expand Down Expand Up @@ -288,13 +291,17 @@ fun subscribe() {
startsWith(listOf("生成", "/生成")) { raw ->
val args = raw.toArgsList()
val images = when (this) {
is GroupAtMessageEvent -> message.filterIsInstance<RemoteImage>().map {
it.getFile().readNativeImage()
is GroupAtMessageEvent -> message.filterIsInstance<RemoteImage>().map { r ->
r.use {
it.readNativeImage()
}
}
is GuildAtMessageEvent -> {
message.filterIsInstance<GuildAt>().filter { it.target != bot.botGuildInfo.id }
.map { it.user.avatar }.ifEmpty { listOf(author.avatar) }.map {
NetworkUtils.downloadTempFile(it)!!.toVfs().readNativeImage()
NetworkUtils.useNetFile(it) { f ->
f.readNativeImage()
}
}
}
else -> return@startsWith
Expand Down Expand Up @@ -339,7 +346,7 @@ fun subscribe() {
reply(ImageGeneration.pincushion(img).toImage())
}
"5k" -> {
val nowArgs = raw.trim().substringAfter("5k").toArgsListByLn()
val nowArgs = raw.trim().substringAfter("5k").toArgsListByLnOrSpace()
when (nowArgs.size) {
0 -> reply("使用方法:\n/生成 5k 第一行文本\n第二行文本(可选)")
1 -> reply(FiveThousandChoyen.generate(nowArgs.first().trim(), " ").encode(PNG).toImage())
Expand Down Expand Up @@ -406,8 +413,9 @@ fun subscribe() {
return@startsWith
}
try {
val image = LaTeX.generateLaTeX(text)
reply(image.toImage())
LaTeX.generateLaTeX(text).useTempFile {
reply(it.toImage())
}
} catch (e: Exception) {
if (e is org.scilab.forge.jlatexmath.ParseException) {
reply(e.message!!)
Expand All @@ -419,7 +427,7 @@ fun subscribe() {
"/gocho", "gocho",
"/choyen", "choyen"
)) { raw ->
val args = raw.toArgsListByLn()
val args = raw.toArgsListByLnOrSpace()
when (args.size) {
0 -> reply("使用方法:\n/5k 第一行文本\n第二行文本(可选)\n\n例:/5k 干什么!")
1 -> reply(FiveThousandChoyen.generate(args.first().trim(), " ").encode(PNG).toImage())
Expand All @@ -445,14 +453,14 @@ fun subscribe() {
}
GlobalEventChannel.subscribePublicMessages(permName = "audio.voice") {
startsWith(listOf("活字印刷", "/活字印刷")) { text ->
if (text.isBlank()) {
reply("使用方法:/活字印刷 文本\n例:/活字印刷 大家好啊,我是可怜Bot")
if (text.isBlank() || text.length >= 120) {
reply("使用方法:/活字印刷 文本\n字数不能超过120个字!\n例:/活字印刷 大家好啊,我是可怜Bot")
return@startsWith
}
audioSemaphore.withPermit {
kotlin.runCatching {
OttoVoice.generate(text) ?.toVoice() ?.let {
reply(it)
OttoVoice.generate(text).useTempFile {
reply(it.toVoice())
}
}.onFailure {
reply("生成失败,请检查内容是否为中文/英文/数字。")
Expand Down Expand Up @@ -527,6 +535,34 @@ fun subscribe() {
}
}
}
GlobalEventChannel.subscribePublicMessages {
startsWith("/restart") {
if (subjectId == "EDC8852148286B84FAB4ECF00D21C378") {
bot.restarting = true
GlobalEventChannel.broadcast(BotRestartEvent(bot))
reply("ok")
}
}
}
GlobalEventChannel.subscribePublicMessages {
startsWith("/test") {
reply("https://www.baidu.com")
}
}
GlobalEventChannel.subscribePublicMessages {
startsWith("/info") {
reply(buildString {
append("Subject ID: ")
appendLine(subjectId)
append("Context ID: ")
appendLine(contextId)
append("Node: ")
append(config.shardId)
append("/")
appendLine(config.shardTotal)
})
}
}
// GlobalEventChannel.subscribePublicMessages(permName = "sleep") {
// equalsTo(listOf("晚安", "/晚安", "睡觉", "/睡觉")) {
// WakeSleep.sleep(contextId, subjectId) ?.let {
Expand Down
49 changes: 18 additions & 31 deletions src/main/kotlin/xyz/xszq/bot/audio/AudioEncodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@ package xyz.xszq.bot.audio
import io.github.kasukusakura.silkcodec.SilkCoder
import korlibs.audio.format.readSoundInfo
import korlibs.io.file.VfsFile
import korlibs.io.file.std.toVfs
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.withContext
import xyz.xszq.bot.ffmpeg.FFMpegFileType
import xyz.xszq.bot.ffmpeg.FFMpegTask
import xyz.xszq.bot.ffmpeg.FFProbe
import xyz.xszq.nereides.newTempFile
import xyz.xszq.nereides.getTempFile
import xyz.xszq.nereides.useTempFile
import java.io.File

val audioSemaphore = Semaphore(16)
val audioSemaphore = Semaphore(64)

suspend fun VfsFile.getAudioDuration(): Double {
return readSoundInfo()?.duration?.seconds ?: FFProbe(
this, showStreams = false, showFormat = true
).getResult().format!!.duration.toDouble()
}
fun File.getAudioDuration(): Double = runBlocking {
toVfs().getAudioDuration()
}

suspend fun File.toMp3BeforeSilk(): File? =
suspend fun VfsFile.toMp3BeforeSilk() =
FFMpegTask(FFMpegFileType.MP3) {
input(this@toMp3BeforeSilk)
yes()
Expand All @@ -36,12 +30,12 @@ suspend fun File.toMp3BeforeSilk(): File? =
audioRate("24k")
audioChannels(1)
}.getResult()
suspend fun File.toMp3(): File? =
suspend fun VfsFile.toMp3() =
FFMpegTask(FFMpegFileType.MP3) {
input(this@toMp3)
yes()
}.getResult()
suspend fun File.toPCM(): File? =
suspend fun VfsFile.toPCM() =
FFMpegTask(FFMpegFileType.PCM) {
input(this@toPCM)
forceFormat("s16le")
Expand All @@ -50,11 +44,11 @@ suspend fun File.toPCM(): File? =
audioChannels(1)
yes()
}.getResult()
suspend fun File.cropPeriod(
suspend fun VfsFile.cropPeriod(
startPoint: Double,
duration: Double,
forSilk: Boolean = true
): File? =
) =
FFMpegTask(FFMpegFileType.MP3) {
input(this@cropPeriod)
yes()
Expand All @@ -65,23 +59,16 @@ suspend fun File.cropPeriod(
audioChannels(1)
}
}.getResult()
suspend fun VfsFile.cropPeriod(
startPoint: Double,
duration: Double,
forSilk: Boolean = true
) = File(absolutePath).cropPeriod(startPoint, duration, forSilk)?.toVfs()
suspend fun File.toSilk(): File {
val silk = newTempFile(suffix = ".silk")
silk.outputStream().use { os ->
toMp3BeforeSilk() ?.toPCM() ?.apply {
SilkCoder.encode(
inputStream(),
os,
24000
)
suspend fun VfsFile.toSilk(): VfsFile {
val silk = getTempFile(suffix = ".silk")
File(silk.absolutePath).outputStream().use { outputStream ->
toMp3BeforeSilk().useTempFile { mp3 ->
mp3.toPCM().useTempFile { pcm ->
File(pcm.absolutePath).inputStream().use { inputStream ->
SilkCoder.encode(inputStream, outputStream, 24000)
}
}
}
}
silk.deleteOnExit()
return silk
}
suspend fun VfsFile.toSilk() = File(absolutePath).toSilk()
}
Loading

0 comments on commit 1eabc7c

Please sign in to comment.