#Recording voice input using microphone
file = "file.mp3"
flag=True
fst="My name is Dan. I will answer your queries about Science. If you want to exit, say Bye"
tts = gTTS(fst, 'en')
tts.save(file)
os.system("mpg123 " + file )
r = sr.Recognizer()
prYellow(fst)
I am working with this error in this area using python and I cannot fix it. Hoping that there's anyone here who can fix this error problem.
Related
Task:
I made this command that should create a file .txt file and if it has a valid name and it does not exist in ListPython.txt. But when I run it I get the error bellow. Could someone please help me?
Code:
#bot.tree.command(name="newpython")
#app_commands.describe(FileName='FileName')
async def newpython(interaction: discord.Interaction,FileName: str):
AddToLog(f'[INFO][{GetTime()}] newpython command has been used')
_ = open("Program Files/ListPython.txt", "r")
_ = _.read()
_ = _.split()
if FileName not in _:
with open("Program Files/ListPython.txt", "a") as file1:
file1.write(f' {FileName}')
try:
f = open(f"Python Files/{FileName}.txt", "x")
await interaction.response.send_message(f"{FileName} created")
except OSError:
await interaction.response.send_message(f"{FileName} is a invalid file name.")
else:
await interaction.response.send_message(f"{FileName} already exists.")
Error:
discord.app_commands.errors.CommandSignatureMismatch: The signature for command 'newpython' is different from the one provided by Discord. This can happen because either your code is out of date or you have not synced the commands with Discord, causing the mismatch in data. It is recommended to sync the command tree to fix this issue.
The problem is not for app_commands because when I removed it I still got the error though I could be wrong because I'm new to discod.py.
I solved the problem with replacing:
#app_commands.describe(FileName='FileName')
with
#app_commands.describe(user='FileName')
I really don't know how this fix the problem but it does
Hoping someone can help me solve this puzzle.
Using python-vlc 3.0.16120 - I'm trying to stream over http from a Python script on Windows.
It works using this command line:
"C:\Program Files\VideoLAN\VLC\vlc.exe" sample-mp4-file.mp4 --sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}", :no-sout-all :sout-keep
However, this code (using the same sout) doesn't seem to work.
import vlc
inst = vlc.Instance("""--sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}", :no-sout-all :sout-keep""")
med = inst.media_new("sample-mp4-file.mp4")
p = med.player_new_from_media()
p.play()
while True:
pass
Does anyone have any suggestions
TIA
This code works- don't ask me why
import vlc
inst = vlc.Instance()
param=[
"sample-mp4-file.mp4"
,"sout=#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}"
]
Media = inst.media_new(*param)
player = Media.player_new_from_media()
player.play()
while True:
pass
I am a Portuguese High Schooler so sorry if I dont make myself very clear but I will try my best to explain my problem.
So for this project I need to make a program that recognises speech and do what is told to do. But if the speech is not recognisable I want the program to try until it finally catches what is being said. However I dont really know how to do that since this "error" keeps appearing: Error
Here is the code if anyone wants to help:
import speech_recognition as sr
import subprocess as sp
import os
def ouvir_microfone():
audio_Input = sr.Recognizer()
with sr.Microphone() as source:
Ray = "ON"
Open = "Open"
print("Hello my name is Ray pleased to help you")
audio_Input.adjust_for_ambient_noise(source)
print("Say something: ")
audio = audio_Input.listen(source)
frase = audio_Input.recognize_google(audio,language='en-US')
if ValueError: print("Speech not recognised")
else: print("You said: " + frase)
if Open in frase:
print('sucess')
ouvir_microfone()
Use try and exception to handle the error
try:
frase = audio_Input.recognize_google(audio,language='en-US')
print("You said: " + frase)
except ValueError:
print("Speech not recognised")
if Open in frase:
print('sucess')
import speech_recognition as sr
import subprocess as sp
import os
def ouvir_microfone():
audio_Input = sr.Recognizer()
with sr.Microphone() as source:
Ray = "ON"
Open = "Open"
print("Hello my name is Ray pleased to help you")
audio_Input.adjust_for_ambient_noise(source)
print("Say something: ")
audio = audio_Input.listen(source)
try:
# valid
frase = audio_Input.recognize_google(audio,language='en-US')
print("You said: " + frase)
except:
# google could not validate
print("Speech not recognised")
return False
if Open in frase:
print('sucess')
return True
while True:
if ouvir_microfone():
# got a valid response
break
Works as a solid template. Some imports also remain unused as a sidenote. Catch the exception and return False if the speech could not be recognized so it retries. The google voice recognition python library throws an exception in the case that no distinguishable speech can be read.
I was trying to code a voice assistant with the help of an online tutorial. When I tried to run the code, I kept kept getting an error message saying:
Error 263 for command:
close voice.mp3
The specified device is not open or is not recognized by MCI.
Failed to close the file: voice.mp3
*Note: "voice.mp3" is the name I gave to the mp3 file.
This is the only function in the program which used "voice.mp3", as well as the Playsound module:
def speak(text):
tts = gTTS(text=text, tld="ca", lang="en")
filename = "voice.mp3"
tts.save(filename)
playsound.playsound(filename)
I believe it has something to do with Playsound.
Does anyone know how to fix this?
I just added ./ to the name of the file in the code.
filename = "./voice.mp3"
I have this function and I need to close the file before exiting the function say("some text").
def say(self, text):
tts = gTTS(text, lang='fr')
file="text.mp3"
tts.save(file)
audio = MP3(file)
p = vlc.MediaPlayer(file)
p.play()
time.sleep((audio.info.length)) #to avoid it listening to itself
p.stop()
return file
Because If I don't do this, I have this error
OS Error: [Errno -9993] Illegal combination of I/O device
I think that this error occurs because I'm trying to listen just after the call of the function say and the file is still open.
nb: I'm working with Python 3
Though i am not to experienced with TTS, shouldnt it work if you just do close(os.getcwd()+'/'+file)?