#telegram bot

1 messages · Page 1 of 1 (latest)

opal kernel
#

I think you should think carefully on what "efficient" means here: are you trying to optimize for the least amount of unnecessary downloads [of voice audio files]? Or of storage space used by saved audio?

#

Because personally, I see the latter being a longer term problem: it makes sense to me that you'd rather avoid a mess than have to clean it up later

cold mango
#

Avoiding a storage mess is a requirement. It would be nice to avoid unnecessary downloads as well, I guess.

So far I have found the picotts integration as one that uses namedtempfiles I need to see how the tts integration manages the clean-up.

#

The part I still don't know if it is possible to implement is how someone who listens to the event and receives the file_id string can retrieve the actual audio file from it...

opal kernel
#

I'd actually say that downloading/keeping it in-memory as an io.BufferedWriter is completely reasonable (especially since python-telegram-bot guarantees a maximum size of 20 mb) if any of the following are true:

  • it's expected that "not too many" voice messages will be downloaded
  • it's expected that whoever is consuming the event will actively, immediately use the audio data, including perhaps to save it to disk for another purpose
  • actually downloading/including the audio data is itself an optional flag/optional return value: aka, someone may only want an event whenever a voice message has been received, rather than actually getting the message itself
opal kernel
# cold mango The part I still don't know if it is possible to implement is how someone who li...

From the documentation: https://docs.python-telegram-bot.org/en/stable/telegram.voice.html#telegram.Voice.file_id
(and from brief passing familiarity with python-telegram-bot)
I'd guess that the file_id is at least unique per registered telegram bot, and would still be usable over time/after restarts.

It also seems that the get_file method itself doesn't even download the File, just prepare it for downloading by way of internal URL which expires in 1+ hour (but can be refreshed using the same file_id

#

So overall, if you end up finding a way to design it such that the file_id is to be used in a callback, that definitely seems to be a very powerful option that would also apply to other data types (pictures/video come to mind)

#

You could probably test the behavior of file_id really quickly on your own with a bot and be sure

cold mango
#

Since I have the bot access token, refreshing the file_id should not be an issue, although I will test it.

The callback approach would be best so we can reuse it for other types as you say. I need to read more to see if it is even possible.

I will start with a quick and dirty solution to motivate myself that it is possible to make it work and once I have it, I'll look into the callback approach, learning how the syntax in the automations pipeline works and if it can be extended.

opal kernel
#

Seems like a reasonable tiered approach! You should be well set

cold mango
#

FYI I think I can implement something similar to our callback approach defining a media_source: https://www.home-assistant.io/integrations/media_source/

After my quick and dirty solution my next step will be to check the tts and the xbox classes to understand how that is implemented. I hope to be able to provide a pull request eventually

cold mango
#

https://github.com/home-assistant/core/pull/83878

Still work in progress but I was able to hear my voice on the speakers.

Feedback is very much welcome. I would be very happy to acknowledge your support there but I didn't know your GitHub handle @opal kernel