Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code help
#1
Photo 
Funcția de recunoaștere vocală
import speechrecognition as sr
from twilio.rest import Client
... def getorder():
...     recognizer = sr.Recognizer()
...     with sr.Microphone() as source:
...         print("Spune comanda pentru mici...")
...         try:
...             audio = recognizer.listen(source)
...             text = recognizer.recognize_google(audio, language="ro-RO")
...             print(f"Comanda înregistrată: {text}")
...             return text
...         except sr.UnknownValueError:
...             print("Nu am înțeles. Te rog să repeți!")
...         except sr.RequestError as e:
...             print(f"Eroare cu serviciul de recunoaștere vocală: {e}")
...     return None
... 
... # Funcția de apelare
... def call_for_mici(order):
...     # Configurațiile Twilio
...     account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'  # SID-ul Twilio
...     auth_token = 'your_auth_token'  # Tokenul de autentificare Twilio
...     client = Client(AC616e0d9e8fba3101f81ecc33a6a28b87, db03d84515ab0da3aa72b3bb9533bdb)
... 
...     # Textul comenzii
...     message = f"Vreau să comand: {order}."
...
...     call = client.calls.create(
...         twiml=f'<Response><Say>{message}</Say></Response>',
...         to="+40761848834",  # Numărul destinatarului
...         from="+40773840975"  # Numărul Twilio asociat contului tău
...     )
...     print(f"Apel inițiat cu SID: {call.sid}")
... 
... # Logica principală
... if name == "main":
...     order = get_order()
...     if order:
...         call_for_mici(order) 
Hello when i click run module on the code in the python idle i get an error on line 2 where the def is invalid syntax does anyone know how i solve this program and make the code run do i need to replace the def or delete some of the code cause it keeps giving me errors as i try to fix the code and debug it,i need some help to find the right solution.
https://imgur.com/a/l8ZY4Nn
Reply
#2
The indentation is wrong. The def should not be indented. Is the first line supposed to be a comment or is that not part of the code? What is the “…” at the start or the lines? It should not be there.
Reply
#3
(Dec-06-2024, 12:47 PM)deanhystad Wrote: The indentation is wrong. The def should not be indented. Is the first line supposed to be a comment or is that not part of the code? What is the “…” at the start or the lines? It should not be there.

the dots are how python idle makes the code so what should i put instead of def so it will run?
Reply
#4
Output:
the dots are how python idle makes the code
You are using the wrong tool.

In IDLE you can type code in the shell, or you can write code in a file. You should almost always enter code in a file window, not the shell.
Reply
#5
(Dec-09-2024, 06:04 PM)deanhystad Wrote:
Output:
the dots are how python idle makes the code
You are using the wrong tool.

In IDLE you can type code in the shell, or you can write code in a file. You should almost always enter code in a file window, not the shell.

you mean the python shorcut?
Reply
#6
When you start IDLE the first screen you see is the IDLE shell. You can type code in the shell, and it is very much like running python and typing in the interactive interpreter. The left margin of the shell displays ">>>" or "...". ">>>" indicates this is a new statement. "..." indcates this is a continuation of the previous statement. If you are writing a python program, this is not the tool to use.

What you want to do is click on the "File" menu and select "New File". This opens a new window. In the left margin of this window you will see line numbers (1, 2, 3) instead of the interactive python prompt (>>> or ...). Type your program in this window. To run the program (or module), you first need to save the file. Once saved you can run the program from IDLE, or you can run using the python executable.

IDLE is not a good software development tool. I suggest you do some research and find a better tool for your platform.
Reply
#7
(Dec-09-2024, 08:22 PM)deanhystad Wrote: When you start IDLE the first screen you see is the IDLE shell. You can type code in the shell, and it is very much like running python and typing in the interactive interpreter. The left margin of the shell displays ">>>" or "...". ">>>" indicates this is a new statement. "..." indcates this is a continuation of the previous statement. If you are writing a python program, this is not the tool to use.

What you want to do is click on the "File" menu and select "New File". This opens a new window. In the left margin of this window you will see line numbers (1, 2, 3) instead of the interactive python prompt (>>> or ...). Type your program in this window. To run the program (or module), you first need to save the file. Once saved you can run the program from IDLE, or you can run using the python executable.

IDLE is not a good software development tool. I suggest you do some research and find a better tool for your platform.
well the only other option is pycharm or visual studio code but those don't have a run module option like python and i can't tell the code errors this way.
Reply
#8
What do you mean by a "run module option"? Both VS Code and PyCharm allow you to run your program of course (PyCharm has a green play button, for example).
Reply
#9
(Dec-10-2024, 05:53 AM)ndc85430 Wrote: What do you mean by a "run module option"? Both VS Code and PyCharm allow you to run your program of course (PyCharm has a green play button, for example).

i didn't seem to find one into visual code studio
Reply
#10
Perhaps you haven't installed the Python extension? See, for example https://code.visualstudio.com/docs/languages/python.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020