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

我尝试着在通过pupeetlocal发送语音的时候还是以文件形式进行发送 #2684

Open
aqpmzngldh opened this issue Apr 30, 2024 · 17 comments

Comments

@aqpmzngldh
Copy link

2024-04-30_152046
我尝试着在通过pupeetlocal发送语音的时候还是以文件形式进行发送

Copy link

dosubot bot commented Apr 30, 2024

To address the issue of sending voice messages via puppeteer that are being sent as files, ensure your code is correctly identifying and handling voice messages. Specifically, you should:

  1. Verify your message type handling aligns with PUPPET.types.Message.Audio for voice messages.
  2. Use the correct method for sending voice messages, which might involve encapsulating the voice file in a FileBox object and sending it using a method designed for voice/audio files.
  3. Before sending, inspect the payload to confirm it's correctly marked as a voice message, including setting the appropriate MIME type.
  4. For detailed guidance, refer to the Wechaty documentation on handling and sending audio messages.

Here's a quick example of how to send a voice message in Wechaty:

import { FileBox }  from 'wechaty'

const fileBox = FileBox.fromFile('/path/to/voice/file.mp3')
await bot.say(fileBox)

Ensure the message is identified as a voice message and use Wechaty's provided methods for handling such messages. If issues persist, more specific details about your implementation and any errors would be helpful for further assistance.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@aqpmzngldh
Copy link
Author

To address the issue of sending voice messages via puppeteer that are being sent as files, ensure your code is correctly identifying and handling voice messages. Specifically, you should:

  1. Verify your message type handling aligns with PUPPET.types.Message.Audio for voice messages.
  2. Use the correct method for sending voice messages, which might involve encapsulating the voice file in a FileBox object and sending it using a method designed for voice/audio files.
  3. Before sending, inspect the payload to confirm it's correctly marked as a voice message, including setting the appropriate MIME type.
  4. For detailed guidance, refer to the Wechaty documentation on handling and sending audio messages.

Here's a quick example of how to send a voice message in Wechaty:

import { FileBox }  from 'wechaty'

const fileBox = FileBox.fromFile('/path/to/voice/file.mp3')
await bot.say(fileBox)

Ensure the message is identified as a voice message and use Wechaty's provided methods for handling such messages. If issues persist, more specific details about your implementation and any errors would be helpful for further assistance.

Details

To continue the conversation, mention @dosu.

就是按照这种方式发送的,但是发送出去还是.silk的文件const voiceFilePath = "F:\typora笔记-其他\小程序1\222\1.silk";

const voiceLength = 2000; // 需要提供语音长度,单位为毫秒
const fileBox = FileBox.fromFile(voiceFilePath);
fileBox.mimeType = "audio/silk";
fileBox.metadata = {
voiceLength,
};

await sendMessage(room.id, fileBox);@dosu.

Copy link

dosubot bot commented May 1, 2024

It looks like you're doing everything correctly for sending a voice message with Wechaty, including setting the MIME type and using a FileBox object. However, if the message is still being sent as a file, this might be due to limitations within the Puppeteer puppet or the way Wechaty handles voice messages, especially with .silk files.

Ensure that the MIME type you're setting (audio/silk) is recognized by the platform you're sending the message to. Sometimes, changing the MIME type to a more commonly supported format (like audio/mp4 or audio/mpeg) can help. Here's a refined example for sending a voice message:

import { FileBox }  from 'file-box';
import { Wechaty } from 'wechaty';

async function sendVoiceMessage(bot: Wechaty, receiverId: string, filePath: string) {
  const fileBox = FileBox.fromFile(filePath, 'audio/mp4'); // Adjust MIME type as necessary
  const contact = await bot.Contact.find({ id: receiverId });
  if (contact) {
    await contact.say(fileBox);
  }
}

This code snippet assumes you're familiar with the receiver's ID and the file path. Adjust the MIME type based on the actual format of your voice file and the capabilities of the receiving platform.

If changing the MIME type doesn't resolve the issue, it could be related to how the specific puppet you're using processes audio messages. Some puppets might not fully support certain audio formats or might handle them as generic files. Reviewing the puppet's documentation or reaching out to the Wechaty community for support with specific file formats like .silk could provide more targeted solutions.

Additionally, consider looking into similar issues reported in the Wechaty GitHub repository, such as problems with MIME types for .silk files or difficulties sending voice messages with certain puppets. These discussions might offer insights or workarounds from other developers who faced similar challenges.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@aqpmzngldh
Copy link
Author

好的,已解决

@aqpmzngldh
Copy link
Author

It looks like you're doing everything correctly for sending a voice message with Wechaty, including setting the MIME type and using a FileBox object. However, if the message is still being sent as a file, this might be due to limitations within the Puppeteer puppet or the way Wechaty handles voice messages, especially with .silk files.

Ensure that the MIME type you're setting (audio/silk) is recognized by the platform you're sending the message to. Sometimes, changing the MIME type to a more commonly supported format (like audio/mp4 or audio/mpeg) can help. Here's a refined example for sending a voice message:

import { FileBox }  from 'file-box';
import { Wechaty } from 'wechaty';

async function sendVoiceMessage(bot: Wechaty, receiverId: string, filePath: string) {
  const fileBox = FileBox.fromFile(filePath, 'audio/mp4'); // Adjust MIME type as necessary
  const contact = await bot.Contact.find({ id: receiverId });
  if (contact) {
    await contact.say(fileBox);
  }
}

This code snippet assumes you're familiar with the receiver's ID and the file path. Adjust the MIME type based on the actual format of your voice file and the capabilities of the receiving platform.

If changing the MIME type doesn't resolve the issue, it could be related to how the specific puppet you're using processes audio messages. Some puppets might not fully support certain audio formats or might handle them as generic files. Reviewing the puppet's documentation or reaching out to the Wechaty community for support with specific file formats like .silk could provide more targeted solutions.

Additionally, consider looking into similar issues reported in the Wechaty GitHub repository, such as problems with MIME types for .silk files or difficulties sending voice messages with certain puppets. These discussions might offer insights or workarounds from other developers who faced similar challenges.

Details

To continue the conversation, mention @dosu.

我现在有一个问题,就是语音可以发送了,但是每次点播放的时候只是叮响一下就没了,就是语音没有内容,但是发送的样式和时长是有了,我的语音是通过wav文件编码转换成的sil文件通过pupeetlocal进行播放的,我不知道哪里的问题,电脑上有一个好久之前的sil文件是可以正常播放,我在想是不是我转换成sil的时候转的有问题还是怎么回事,因为我看之前那个可以播放的文件同样的时长但是文件特别小

Copy link

dosubot bot commented May 1, 2024

The issue with the .silk files not playing correctly, despite showing the correct style and duration, likely stems from the conversion process from WAV to .silk format. If there's a noticeable difference in file size compared to a .silk file that plays correctly, this indicates a potential problem in how the files are being converted or compressed.

To troubleshoot, compare the properties (bitrate, sample rate, encoding settings) of a working .silk file with your newly generated files. This comparison can help pinpoint discrepancies that might be causing playback issues.

For error tracking and more insights, if Wechaty's Raven (Sentry) integration is enabled, it can capture and log playback errors. This could provide valuable information for diagnosing the problem.

Remember, the FileBox class and say method are used for sending voice messages in Wechaty. Ensuring your files are correctly formatted and compatible with Wechaty's requirements is crucial for successful playback.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@914375390
Copy link

可以问下是怎么解决的吗,一直发的是文件@ @aqpmzngldh

@aqpmzngldh
Copy link
Author

可以问下是怎么解决的吗,一直发的是文件@ @aqpmzngldh

加我,v:weixinsou_qianxiaoye

Copy link

dosubot bot commented May 9, 2024

问题已经解决的关键在于确保语音文件的格式和编码正确转换成目标平台支持的格式。在这个案例中,用户最初遇到的问题是通过Wechaty发送的.silk格式语音文件被作为文件而不是语音消息发送。解决方法包括调整MIME类型以确保平台兼容性,并确保使用正确的方法和对象(如Wechaty的FileBox)来发送语音消息。

对于语音内容播放时只有短暂的声音而没有实际内容的问题,这通常是由于文件转换过程中的问题,比如编码设置不正确或者文件压缩过度导致。确保使用正确的转换工具和设置来生成目标格式的文件是解决这个问题的关键。比较一个已知可以正常播放的.silk文件和问题文件的属性(比如比特率、采样率和编码设置)可以帮助识别和解决问题。

如果你遇到类似问题,检查文件转换过程和设置,并确保目标文件格式与发送平台和Wechaty的要求兼容。此外,利用Wechaty社区和文档资源来获取更多关于文件格式和编码的指导也是非常有帮助的。

Details

About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@aqpmzngldh
Copy link
Author

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

@nicholasDxy
Copy link

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢!
这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

@aqpmzngldh
Copy link
Author

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢! 这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

我没出现过你说的现象,你用的是哪个puppet呢,我可以给你提供这个接口

@nicholasDxy
Copy link

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢! 这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

我没出现过你说的现象,你用的是哪个puppet呢,我可以给你提供这个接口

谢谢! 我用的是workpro的puppet,以企业微信方式登录的. 但是我的问题应该是出在生成的silk文件上,我是将mp3文件转换成silk文件之后发送的,发到微信上就有的时候没办法播放.还想问下你的silk文件是怎样生成的呢

@aqpmzngldh
Copy link
Author

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢! 这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

我没出现过你说的现象,你用的是哪个puppet呢,我可以给你提供这个接口

谢谢! 我用的是workpro的puppet,以企业微信方式登录的. 但是我的问题应该是出在生成的silk文件上,我是将mp3文件转换成silk文件之后发送的,发到微信上就有的时候没办法播放.还想问下你的silk文件是怎样生成的呢

好的,明天我有空写个接口给你,以后调他给你转silk就好了

@nicholasDxy
Copy link

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢! 这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

我没出现过你说的现象,你用的是哪个puppet呢,我可以给你提供这个接口

谢谢! 我用的是workpro的puppet,以企业微信方式登录的. 但是我的问题应该是出在生成的silk文件上,我是将mp3文件转换成silk文件之后发送的,发到微信上就有的时候没办法播放.还想问下你的silk文件是怎样生成的呢

好的,明天我有空写个接口给你,以后调他给你转silk就好了

非常感谢!!

@nicholasDxy
Copy link

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢! 这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

我没出现过你说的现象,你用的是哪个puppet呢,我可以给你提供这个接口

谢谢! 我用的是workpro的puppet,以企业微信方式登录的. 但是我的问题应该是出在生成的silk文件上,我是将mp3文件转换成silk文件之后发送的,发到微信上就有的时候没办法播放.还想问下你的silk文件是怎样生成的呢

好的,明天我有空写个接口给你,以后调他给你转silk就好了

感谢大佬,这我找到问题所在了,因为我用的fromFile的接口,导致语音时长没生效,我换成fromUrl加载就没有问题了,谢谢大佬解答!

@aqpmzngldh
Copy link
Author

关于这个问题的错误分两种,1,有可能你用的puppet不支持语音发送;2.有可能你的silk文件格式有问题,大家仔细检查就不会出现这个问题了

你好大佬,想请教下你是用什么工具生成的silk文件呢,我用python的pilk库生成的silk文件,然后使用语音发送到微信.但是有概率出现微信语音播放不了的现象,大部分情况还是可以正常播放的,想请问下你有遇到过这样的现象吗.非常感谢! 这是我发送语音的代码:

const fileBox = FileBox.fromFile(reply.audioPath)
fileBox.mimeType = "audio/silk";
talker.say(fileBox)

我没出现过你说的现象,你用的是哪个puppet呢,我可以给你提供这个接口

谢谢! 我用的是workpro的puppet,以企业微信方式登录的. 但是我的问题应该是出在生成的silk文件上,我是将mp3文件转换成silk文件之后发送的,发到微信上就有的时候没办法播放.还想问下你的silk文件是怎样生成的呢

好的,明天我有空写个接口给你,以后调他给你转silk就好了

感谢大佬,这我找到问题所在了,因为我用的fromFile的接口,导致语音时长没生效,我换成fromUrl加载就没有问题了,谢谢大佬解答!

对,我用的也是url

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

3 participants