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

获取群语音下载链接失败 #2269

Closed
Aye10032 opened this issue Oct 6, 2022 · 4 comments
Closed

获取群语音下载链接失败 #2269

Aye10032 opened this issue Oct 6, 2022 · 4 comments
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:problem 类型: 不容易归类为特性或 bug 的综合问题 x:protocol 属性: 协议相关
Milestone

Comments

@Aye10032
Copy link

Aye10032 commented Oct 6, 2022

问题描述

简要描述一下,现在代码逻辑是先从MessageEvent中通过event.getMessage()方法获得到MessageChain,之后再通过chain.get(OnlineAudio.Key)获得到OnlineAudio的对象,但是通过(audio).getUrlForDownload()拿下载URL的时候如果是群语音就会报错,拿不到,但是如果是私聊发送的语音就可以拿到URL,下载下来解码之后也可以正常播放

直接调用报错的部分

public File getAudioFromMsg(SimpleMsg msg) {
        File silk_file;
        try {
            MessageChain chain = msg.getMsgChain();
            OnlineAudio audio = chain.get(OnlineAudio.Key);
            assert audio != null;

            silk_file = new File(appDirectory + "/origin.silk");
            byte[] bytes1 = IOUtils.toByteArray(new URL((audio).getUrlForDownload()));
            BufferedOutputStream silk_out = new BufferedOutputStream(Files.newOutputStream(silk_file.toPath()));
            silk_out.write(bytes1);
            silk_out.flush();
            silk_out.close();

            File mp3_file;
            AudioUtils.init(new File(appDirectory + "/audio"));
            mp3_file = AudioUtils.silkToMp3(silk_file);

            return mp3_file;
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

其中SimpleMsg是自己对消息信息的二次封装,涉及的部分代码如下

    public SimpleMsg(MessageEvent event) {
        if (event instanceof GroupMessageEvent) {
            type = MsgType.GROUP_MSG;
            fromGroup = ((GroupMessageEvent) event).getGroup().getId();
        } else if (event instanceof FriendMessageEvent) {
            type = MsgType.PRIVATE_MSG;
        } else if (event instanceof GroupTempMessageEvent) {
            type = MsgType.PRIVATE_MSG;
        }
        fromClient = event.getSender().getId();
        msg = getMsgFromEvent(event);
        msgChain = event.getMessage();
        this.event = event;
    }

    /**
     * 获取MessageChain对象 用于处理非文本信息
     * @return MessageChain对象
     */
    public MessageChain getMsgChain() {
        return msgChain;
    }

只有群聊中的语音信息会出现问题

复现

  1. 从MessageEvent中通过event.getMessage()方法获得到MessageChain
  2. 通过chain.get(OnlineAudio.Key)获得到OnlineAudio的对象
  3. 通过(audio).getUrlForDownload()获取下载链接
  4. 在群聊中发送语音触发事件,报错,Could not fetch URL for audio

mirai-core 版本

2.13.0-RC

bot-protocol

ANDROID_PHONE

其他组件版本

No response

系统日志

[0m2022-10-06 17:11:43 V/zibenbot: [龙、野兽和火星人猎团(9*******7)] 战 犯 人(2******7) ->[mirai:audio:ED6B21E60B7AC241AD884070AE82E36B.amr]
[91m2022-10-06 17:11:43 W/zibenbot: java.lang.UnsupportedOperationException: Could not fetch URL for audio ED6B21E60B7AC241AD884070AE82E36B.amr

net.mamoe.mirai.internal.message.OnlineAudioImpl.getUrlForDownload(OnlineAudioImpl.kt:118)
com.aye10032.Zibenbot.getAudioFromMsg(Zibenbot.java:784)
com.aye10032.functions.AudioFunction.lambda$new$0(AudioFunction.java:43)
com.dazo66.command.Commander.execute(Commander.java:65)
com.aye10032.functions.AudioFunction.run(AudioFunction.java:88)
com.aye10032.Zibenbot.runFuncs(Zibenbot.java:844)
com.aye10032.Zibenbot.lambda$startup$4(Zibenbot.java:222)
net.mamoe.mirai.event.EventChannel$subscribeAlways$2$1.invoke(EventChannel.kt:574)
net.mamoe.mirai.event.EventChannel$subscribeAlways$2$1.invoke(EventChannel.kt:574)
kotlinx.coroutines.InterruptibleKt.runInterruptibleInExpectedContext(Interruptible.kt:46)
kotlinx.coroutines.InterruptibleKt.access$runInterruptibleInExpectedContext(Interruptible.kt:1)
kotlinx.coroutines.InterruptibleKt$runInterruptible$2.invokeSuspend(Interruptible.kt:38)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

网络日志

No response

补充信息

No response

@Karlatemp
Copy link
Member

发送语音用的是什么客户端 windows pc还是什么其他的

@Aye10032
Copy link
Author

Aye10032 commented Oct 6, 2022

发送语音用的是什么客户端 windows pc还是什么其他的

我这边是用的Android TIM
刚才用Android QQ试了下也报错,PC没用试

@Karlatemp Karlatemp added the s:core 子系统: mirai-core label Oct 6, 2022
@Karlatemp
Copy link
Member

for mamoe: downPara no longer available

@Him188 Him188 added x:protocol 属性: 协议相关 M 优先级: 主要 t:problem 类型: 不容易归类为特性或 bug 的综合问题 labels Oct 6, 2022
@Him188 Him188 added this to the Backlog milestone Oct 6, 2022
@xiaokun5460
Copy link

同序列化 MessageChain.serializeToJsonString(messages); 也会偶发.

 java.lang.UnsupportedOperationException: Could not fetch URL for audio AE932C672DE3A92CD42EEEBD5158D2E5.amr
	at net.mamoe.mirai.internal.message.data.OnlineAudioImpl.getUrlForDownload(audio.kt:118)
	at net.mamoe.mirai.internal.message.data.OnlineAudioImpl$Serializer$special$$inlined$map$1.serialize(Serialization.kt:103)
	at net.mamoe.mirai.internal.message.data.OnlineAudioImpl$Serializer.serialize(audio.kt)
	at net.mamoe.mirai.internal.message.data.OnlineAudioImpl$Serializer.serialize(audio.kt:166)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:228)
	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:80)
	at kotlinx.serialization.internal.ListLikeSerializer.serialize(CollectionSerializers.kt:69)
	at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:274)
	at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:269)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:219)
	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:80)
	at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$SerialData.write$Self(MessageSerializersImpl.kt:41)
	at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$SerialData$$serializer.serialize(MessageSerializersImpl.kt:41)
	at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$SerialData$$serializer.serialize(MessageSerializersImpl.kt:41)
	at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl$special$$inlined$map$1.serialize(Serialization.kt:70)
	at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl.serialize(MessageSerializersImpl.kt)
	at net.mamoe.mirai.internal.message.MessageSourceSerializerImpl.serialize(MessageSerializersImpl.kt:28)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:228)
	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:80)
	at kotlinx.serialization.internal.ListLikeSerializer.serialize(CollectionSerializers.kt:69)
	at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:274)
	at net.mamoe.mirai.message.data.MessageChain$Serializer.serialize(MessageChain.kt:269)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:219)
	at kotlinx.serialization.json.Json.encodeToString(Json.kt:85)
	at net.mamoe.mirai.message.data.MessageChain$Companion.serializeToJsonString(MessageChain.kt:326)
	at net.mamoe.mirai.message.data.MessageChain$Companion.serializeToJsonString$default(MessageChain.kt:324)
	at net.mamoe.mirai.message.data.MessageChain$Companion.serializeToJsonString(MessageChain.kt)
	at net.mamoe.mirai.message.data.MessageChain.serializeToJsonString(MessageChain.kt)

@Him188 Him188 modified the milestones: Backlog, 2.13.0-RC2 Oct 10, 2022
Him188 pushed a commit that referenced this issue Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M 优先级: 主要 s:core 子系统: mirai-core t:problem 类型: 不容易归类为特性或 bug 的综合问题 x:protocol 属性: 协议相关
Projects
None yet
Development

No branches or pull requests

4 participants