telegram-bot-api icon indicating copy to clipboard operation
telegram-bot-api copied to clipboard

broken voice message spectrogram

Open magrega opened this issue 2 years ago • 8 comments

broken voice message spectrogram

Steps to reproduce

Just try sending any voice message (.ogg file, opus encoder) with sendVoiceAsync() that is longer than 10-15 minutes

await using Stream stream = System.IO.File.OpenRead(@"C:\Users\magrega\YandexDisk\проги\audio.ogg"); await client.SendVoiceAsync( chatId: message.Chat.Id, voice: new InputOnlineFile(stream), duration: 1097);

Expected behavior

Voice is sent as any other voice message with actual soundwaves image

Actual behavior

sound spectrogram is flat

Screenshots

image

Additional info

The voice message works properly except for the broken spectrogram. If clicked with right mouse key and Saved as, then after downloading the audio spectrogram refreshes and is visible. How to refresh it on upload to a chat?

Environment data

NuGet Package Version: 18.0.0

.NET Version: .NET 6.0

IDE: VS2022

App: iOS, Win10

magrega avatar Jan 22 '23 06:01 magrega

This is expected behavior for voice messages bigger than 1 MB, for which waveform can't be generated server-side. As documented, such voice messages can't be uploaded by URL at all, and if uploaded as file they have only properties passed during the upload.

levlam avatar Jan 22 '23 07:01 levlam

I’m new to this so if you could elaborate a bit and tell me why the waveform is okay when I upload the same file from recorder app on my phone?

I did an experiment. I took the same mp3 file. Converted it to m4a and saved in my recordings in the recorder app on iOS. Then from that app I shared that m4a audio to a chat in telegram and after uploading the file was perfectly fine with a proper waveform and such.

Is there a way I could handle waveforms the other way so that in the end I get a nice audio with all the spectrograms in all the right places?

waveform can't be generated server-side

but how then the forms are generated when you save this audio locally? After downloading they refresh somehow.

magrega avatar Jan 22 '23 07:01 magrega

I’m new to this so if you could elaborate a bit and tell me why the waveform is okay when I upload the same file from recorder app on my phone?

The waveform is generated by the app, which uploads the file. Bot API doesn't support bot-side waveform generation.

By the way, waveform is useless and irrelevant for long files anyway, because it shows samples from too distant points.

levlam avatar Jan 22 '23 07:01 levlam

Still I care for aesthetic reasons. I think it's better than a dead man's pulse. So I have to generate waveforms from my app and then send it with stream to bot chat, is that right?

magrega avatar Jan 22 '23 07:01 magrega

If the file was uploaded by some other means with a waveform, then it can be sent by the bot via file_id with the same waveform.

levlam avatar Jan 23 '23 06:01 levlam

If the file was uploaded by some other means with a waveform, then it can be sent by the bot via file_id with the same waveform.

Well, I've tried sending the m4a from recorder as a voice with the bot, the result is the same. What means can I use to upload files differently from Stream to preserve waveforms? An example at least.

magrega avatar Jan 23 '23 10:01 magrega

Waveforms for voice messages bigger than 1 MB are added by the app, which uploads the file. There is no way to add a waveform through Bot API.

levlam avatar Jan 23 '23 10:01 levlam

okay, got it.

magrega avatar Jan 23 '23 11:01 magrega