M
M
merchfck2022-02-13 19:30:09
Python
merchfck, 2022-02-13 19:30:09

How to send a message to VK as a voice message?

You need to convert a message from a conversation to a voice message. Converting and saving the audio file exits, but uploading the file to VK and sending it as a GS is no longer possible. What am I doing wrong?

def bot_send():
        global engine, voices
        engine = pyttsx3.init()
        voices = engine.getProperty('voices')
        ru_voice_id = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_RU-RU_IRINA_11.0'
        engine.setProperty('voice', ru_voice_id)

    app = Flask(__name__)
    @app.route('/', methods = ["POST"])
    def main():
        if "/гс" in msg:
            bot_send()
            tts = gTTS(text=msg, lang='ru')
            tts.save("saved_file.mp3")
            a = vk.method("docs.getMessagesUploadServer", {"type": "audio_message", "peer_id": id})
            b = requests.post(a['upload_url'], files={'file': open("C:/bot/saved_file.mp3", 'rb')}).json()
            c = vk.method("docs.save", {"file": b["file"]})[0]
            d = 'doc{}_{}'.format(c['owner_id'], c['id'])
            vk.method('messages.send', {'peer_id': id, 'attachment': d, "random_id": 0})
     
        return "ok"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question