Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an ``.ogg`` file encoded with OPUS , or in .MP3 format, or in .M4A format (other formats may be sent as :class:`
(
self,
chat_id: int | str,
voice: "FileInput | Voice",
duration: TimePeriod | None = None,
caption: str | None = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_markup: "ReplyMarkup | None" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Sequence["MessageEntity"] | None = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int | None = None,
reply_parameters: "ReplyParameters | None" = None,
business_connection_id: str | None = None,
message_effect_id: str | None = None,
allow_paid_broadcast: bool | None = None,
direct_messages_topic_id: int | None = None,
suggested_post_parameters: "SuggestedPostParameters | None" = None,
*,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: int | None = None,
filename: str | None = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict | None = None,
)
| 2643 | ) |
| 2644 | |
| 2645 | async def send_voice( |
| 2646 | self, |
| 2647 | chat_id: int | str, |
| 2648 | voice: "FileInput | Voice", |
| 2649 | duration: TimePeriod | None = None, |
| 2650 | caption: str | None = None, |
| 2651 | disable_notification: ODVInput[bool] = DEFAULT_NONE, |
| 2652 | reply_markup: "ReplyMarkup | None" = None, |
| 2653 | parse_mode: ODVInput[str] = DEFAULT_NONE, |
| 2654 | caption_entities: Sequence["MessageEntity"] | None = None, |
| 2655 | protect_content: ODVInput[bool] = DEFAULT_NONE, |
| 2656 | message_thread_id: int | None = None, |
| 2657 | reply_parameters: "ReplyParameters | None" = None, |
| 2658 | business_connection_id: str | None = None, |
| 2659 | message_effect_id: str | None = None, |
| 2660 | allow_paid_broadcast: bool | None = None, |
| 2661 | direct_messages_topic_id: int | None = None, |
| 2662 | suggested_post_parameters: "SuggestedPostParameters | None" = None, |
| 2663 | *, |
| 2664 | allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE, |
| 2665 | reply_to_message_id: int | None = None, |
| 2666 | filename: str | None = None, |
| 2667 | read_timeout: ODVInput[float] = DEFAULT_NONE, |
| 2668 | write_timeout: ODVInput[float] = DEFAULT_NONE, |
| 2669 | connect_timeout: ODVInput[float] = DEFAULT_NONE, |
| 2670 | pool_timeout: ODVInput[float] = DEFAULT_NONE, |
| 2671 | api_kwargs: JSONDict | None = None, |
| 2672 | ) -> Message: |
| 2673 | """ |
| 2674 | Use this method to send audio files, if you want Telegram clients to display the file |
| 2675 | as a playable voice message. For this to work, your audio must be in an ``.ogg`` file |
| 2676 | encoded with OPUS , or in .MP3 format, or in .M4A format (other formats may be sent as |
| 2677 | :class:`~telegram.Audio` or :class:`~telegram.Document`). Bots can currently send voice |
| 2678 | messages of up to :tg-const:`telegram.constants.FileSizeLimit.FILESIZE_UPLOAD` in size, |
| 2679 | this limit may be changed in the future. |
| 2680 | |
| 2681 | Note: |
| 2682 | To use this method, the file must have the type :mimetype:`audio/ogg` and be no more |
| 2683 | than :tg-const:`telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE` in size. |
| 2684 | :tg-const:`telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE`- |
| 2685 | :tg-const:`telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD` voice notes will be |
| 2686 | sent as files. |
| 2687 | |
| 2688 | .. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>` |
| 2689 | |
| 2690 | Args: |
| 2691 | chat_id (:obj:`int` | :obj:`str`): |chat_id_channel| |
| 2692 | voice (:obj:`str` | :term:`file object` | :class:`~telegram.InputFile` | :obj:`bytes` \ |
| 2693 | | :class:`pathlib.Path` | :class:`telegram.Voice`): Voice file to send. |
| 2694 | |fileinput| |
| 2695 | Lastly you can pass an existing :class:`telegram.Voice` object to send. |
| 2696 | |
| 2697 | .. versionchanged:: 13.2 |
| 2698 | Accept :obj:`bytes` as input. |
| 2699 | |
| 2700 | .. versionchanged:: 20.0 |
| 2701 | File paths as input is also accepted for bots *not* running in |
| 2702 | :paramref:`~telegram.Bot.local_mode`. |