You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im a beginner in programming and I'm having a lot of trouble making my first Pynecone app.
How do I incorporate the following code? (it is a STT translation app).
Many thanks
`import speech_recognition as sr
from googletrans import Translator
import textwrap
def get_mic_input():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
#print("Please speak to the microphone...")
audio = recognizer.listen(source)
try:
text = recognizer.recognize_google(audio)
#print(f"Recognized Text: {text}")
return text
except Exception as e:
# print(f"Error: {e}")
return None
def translate_text(text_to_translate, target_language="pt"):
translator = Translator()
# Wrap the text to 80 characters per line
wrapped_text = textwrap.fill(text_to_translate, width=80)
translation = translator.translate(wrapped_text, dest=target_language)
return translation.text
add a separator line
print("-" * 30)
if name == "main":
while True:
input_text = get_mic_input()
if input_text is not None:
input_text = input_text.lower()
if input_text == "stop" or input_text == "exit":
print("Exiting the loop...")
break
else:
# add a separator line
print("-" * 30)
translated_text = translate_text(input_text)
print(f"PORTUGUES: {translated_text}")
# add a separator line
print("-" * 30)
#else:
#print("Failed to recognize the speech.")`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello
Im a beginner in programming and I'm having a lot of trouble making my first Pynecone app.
How do I incorporate the following code? (it is a STT translation app).
Many thanks
`import speech_recognition as sr
from googletrans import Translator
import textwrap
def get_mic_input():
recognizer = sr.Recognizer()
def translate_text(text_to_translate, target_language="pt"):
translator = Translator()
# Wrap the text to 80 characters per line
wrapped_text = textwrap.fill(text_to_translate, width=80)
translation = translator.translate(wrapped_text, dest=target_language)
return translation.text
add a separator line
print("-" * 30)
if name == "main":
while True:
input_text = get_mic_input()
Beta Was this translation helpful? Give feedback.
All reactions