Module: ChatgptAssistant::Bots::Telegram::VoiceActions
- Included in:
- TelegramBot
- Defined in:
- lib/chatgpt_assistant/bots/telegram/voice_actions.rb
Instance Method Summary collapse
- #telegram_audio ⇒ Object
- #telegram_audio_info ⇒ Object
- #telegram_audio_url ⇒ Object
- #telegram_process_ai_voice(user_audio) ⇒ Object
- #telegram_send_voice_message(voice: nil, text: nil) ⇒ Object
Instance Method Details
#telegram_audio ⇒ Object
15 16 17 |
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 15 def telegram_audio msg.audio || msg.voice end |
#telegram_audio_info ⇒ Object
7 8 9 |
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 7 def telegram_audio_info bot.api.get_file(file_id: telegram_audio.file_id) end |
#telegram_audio_url ⇒ Object
11 12 13 |
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 11 def telegram_audio_url "https://api.telegram.org/file/bot#{telegram_token}/#{telegram_audio_info["result"]["file_path"]}" end |
#telegram_process_ai_voice(user_audio) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 19 def telegram_process_ai_voice(user_audio) ai_text = chatter.chat(user_audio["text"], user.current_chat_id, [:something_went_wrong]) ai_voice = synthesis.synthesize_text(ai_text) { voice: ai_voice, text: ai_text } end |
#telegram_send_voice_message(voice: nil, text: nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 28 def (voice: nil, text: nil) = text, 4096 bot.api.send_voice(chat_id: msg.chat.id, voice: Faraday::UploadIO.new(voice, "audio/mp3")) .each { || , msg.chat.id } end |