Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java 项目应该怎么使用呢 #8

Open
jiashu1024 opened this issue Oct 25, 2023 · 1 comment
Open

java 项目应该怎么使用呢 #8

jiashu1024 opened this issue Oct 25, 2023 · 1 comment

Comments

@jiashu1024
Copy link

我用 mirai core 的 jar 包基于 java 开发,我应该怎么使用来解决格式转换问题呢

@AkagawaTsurunaki
Copy link

build.gradle.kts 文件中添加依赖:

dependencies {
    implementation("net.mamoe:mirai-silk-converter:0.0.5")
}

然后在代码中导入相应的包:

import net.mamoe.mirai.silkconverter.SilkConverter

在实际业务中编写代码,例如我们需要从本地加载一个音频文件 file,并将其作为语音消息发送给某个好友 friend,具体实现代码样例如下:

file?.toExternalResource()?.use { resource -> // 安全地使用资源
    var convertedRes: ExternalResource? = null
    try {
        convertedRes = SilkConverter().convert(resource) // 调用 Silk 转换器进行资源转换
        val audio = friend.uploadAudio(convertedRes) // 上传语音资源
        friend.sendMessage(audio) // 给某个朋友发送语音消息
    } catch (e: Exception) {
        logger.error(e)
    } finally {
        resource.close()
        convertedRes?.close()
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants