-1

python voice to email not working. Everything works just fine. It records and gives me my message output, but it doesn't send the password.

import speech_recognition as sr
import yagmail

recognizer=sr.Recognizer()

with sr.Microphone() as source:
 print('clearing background noises:')

 recognizer.adjust_for_ambient_noise(source,duration=1)
 print("waiting for your message...")

 recordedaudio = recognizer.listen(source)
 print('done recording...!')

 try:
  print('printing the message..')
  text=recognizer.recognize_google(recordedaudio,language='en,US')

  print('Your message:{}'.format(text))

 except Exception as ex:
  print(ex)

  #automate mails:

  reciever='dipinak@gmail.com'
  message=text

  sender=yagmail.SMTP('manas.rdp@gmail.com')
  sender.send(to=reciever,subject='this is an automated email written by manas using python',contents=message)
ppwater
  • 2,315
  • 4
  • 15
  • 29
  • 1
    Show your effort, instead of asking for a ready solution. Show specific errors you need help with and example output that you expect. – Ron Dec 12 '21 at 05:04
  • 1
    sorry ron,i'm new to python and stack overflow ,I don't know how things roll here. will try my best next time. – Mayukh Renish Dec 12 '21 at 05:38
  • but the issue is not solved yet. – Mayukh Renish Dec 12 '21 at 05:39
  • 1
    As a guide: Questions seeking code help must include the shortest code necessary to reproduce it in the question itself preferably in a [Stack Snippet](https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/?more_on=xron.net). See How to create a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). It also very helpful to show in your Question an expected result, and quote any (exact) errors you are getting. You are expected to show any research you have put into solving this question yourself. – Ron Dec 12 '21 at 06:18
  • According to the indentation in the snippet, the emailing part belongs to the `except` block. Indent the last few lines to the left. – Shanavas M Dec 17 '21 at 17:39

1 Answers1

0

after you get your txt message you can send it like this, if you want to add the voice message itself you can attach that as well. Note: It is possible that google tries to block the app if the security does not meet their criteria.

import yagmail

# beforehand, you take your message text here...

try:
    password = 'yourpasshere'
    sender = 'youremail@gmail.com'
    recv = 'reciever@gmail.com'
    msg = 'Your message:{}'.format(text)
    #in case you want to attach a voice message
    attach = '/path_to_your_voice_mesage/test.mp3'

    #initializing the server connection
    yag = yagmail.SMTP(user=sender, password=password)
    #sending the email

    yag.send(to=recv, subject='voice', smtp_ssl=False,
                contents=msg, attachments=attach)
except:
    print("Error, email was not sent")
else:
    print('Email sent successfully :)')

Dariyoush
  • 500
  • 4
  • 16
  • no no i dont think you get me ,but thanks for the password part ,but I wanted to convert my voice to text and the send the text to yagmail/email – Mayukh Renish Dec 12 '21 at 13:47