import pyttsx3
engine=pyttsx3.init('dummy')
engine.say('Hello')
engine.runAndWait()
While I am executing the following code, I am not getting any errors but I am not getting any voice from the system.Help me what I want to do.
This should work:
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello")
engine.runAndWait()
Actually 'dummy' is a test driver that does not do anything. Try using 'sapi5' or leave it empty.
import pyttsx3 engine=pyttsx3.init('sapi5')
(or)
import pyttsx3 engine=pyttsx3.init()
Hope it works!
Related
I am getting a error while running a pttsx3 code as root. So the code should save a file and say the words inputted. Here is the code:
import pyttsx3
engine = pyttsx3.init()
s1 = input("Words: ")
engine.say(s1)
engine.save_to_file(s1 ,'try.mp3')
engine.runAndWait()
And here is the error:
ALSA lib pcm_dmix.c:1035:(snd_pcm_dmix_open) unable to open slave
aplay: main:831: audio open error: Device or resource busy
Running this code without root works, but I need to run it as root because I am adding it to another code that needs root. Note: I tried using gtts but I need a male voice to beatbox.
I ma trying to run the Audio in loop in google colab but it is not giving mi any output
from gtts import gTTS
from IPython.display import Audio
for voice in ["Aniket","sachin"]:
tts = gTTS("Hello {}".format(voice))
tts.save('1.wav')
sound_file = '1.wav'
Audio(sound_file, autoplay=True)
Output what I want is it should sound hello aniket hello sachin Pleas help
You only need to use "IPython.display.display" method as follows :
from gtts import gTTS
from IPython.display import Audio
from IPython.display import display
for voice in ["Aniket","sachin"]:
tts = gTTS("Hello {}".format(voice))
tts.save('1.wav')
sound_file = '1.wav'
wn = Audio(sound_file, autoplay=True) ##
display(wn)##
you can monkey patch audio to do it piggybacking on the autoplay:
a = Audio(...)
a.autoplay_attr = lambda: 'autoplay="autoplay" loop="loop"'
Hello I have made a code:
from gtts import gTTS
import os
import playsound
from pip._vendor.distlib.compat import raw_input
u = raw_input('type: ')
def player(textg):
tts = gTTS(text = textg, lang='en')
tts.save('name.mp3')
playsound('name.mp3')
player(u)
An error comes that:
playsound('name.mp3')
TypeError: 'module' object is not callable
Please Help Me, i am using Python2.7.15
You're importing the whole module, not a method within it.
You'd need to do something like
from playsound import playsound
case your method is called playsound
you should either import the specific method or call playsound method of the playsound module that you imported already:
playsound.playsound('name.mp3')
I'm trying to run a speech recognition using the Speech Recognition Project
I installed SpeechRecognition as illustrated. My code ran correctly for a few times.
I was trying to input different files. Now I started getting the following error:
import speech_recognition as sr
Traceback (most recent call last):
File "<ipython-input-1-a4d5c9aae5d0>", line 1, in <module>
import speech_recognition as sr
File "/Users/Sashank/Documents/Deep_Learning_A_Z/Personal Projects/Speech recognition/speech_recognition.py", line 7, in <module>
r = sr.Recognizer()
AttributeError: module 'speech_recognition' has no attribute 'Recognizer'
The confusing thing is that I'm only executing the first line of the code, which is to import the library. And it returns the error.
import speech_recognition as sr
And the error seems to be corresponding to the next line of code, which I've not yet executed:
r = sr.Recognizer()
I'm new to both programming as well as to python. I'm using spyder3. I've restarted the kernel a few times. I tried to install SpeechRecognition again on terminal. I closed and opened spyder also a few times, but now facing the same error again and again.
Please help.
Full Code:
# Speech Recognition
# Importing Library
import speech_recognition as sr
# Creating a recognition object
r = sr.Recognizer()
# Extracting the audio & removing ambient noice
audio_file = sr.AudioFile('ambient_noise_recording.wav')
with audio_file as source:
r.adjust_for_ambient_noise(source)
audio = r.record(source)
# Recognize the audio
r.recognize_google(audio)
File "/Users/Sashank/Documents/Deep_Learning_A_Z/Personal Projects/Speech recognition/speech_recognition.py", line 7, in
Your name of the file is speech_recognition.py and python is looking not to the speech_recognition module but search the Recognizer in your module (file).
You need simple to rename your module (file).
For example from speech_recognition.py to sp_recog.py
I would like to now how to convert text to speech in python.
In .NET i used
Dim SAPI
Msg = 'Hi this is a test'
SAPI = CreateObject("sapi.spvoice")
SAPI.Speak(Msg)
You can achieve it by pyttsx module. it uses default MS speech recognition system.
import pyttsx
engine = pyttsx.init()
engine.say("Your Message")
engine.runAndWait()
I know its real late to answer here, But I thought I would post here since I have solution based on TTS conversion using SAPI in python, which was OP's original question.
This may be useful for anyone else looking for solution using SAPI in python.
from win32com.client import constants, Dispatch
Msg = "Hi this is a test"
speaker = Dispatch("SAPI.SpVoice") #Create SAPI SpVoice Object
speaker.Speak(Msg) #Process TTS
del speaker #Delete speaker object and free up memory
import pyttsx3
speaker=pyttsx3.init()
speaker.say("Your message")
speaker.runAndWait()
# pip install pywin32
# pip install pyttsx3
import pyttsx3
pyttsx3.speak('Hello Woeld')
You can do it by using the gTTS module. It converts the text to speech.
The second module you have to use is playsound to play the converted text.
from gtts import gTTS #pip install gtts
import playsound #pip install playsound
import os
my_aud = gTTS("hello how are you") #converts the text into speech
my_aud.save('demo.mp3') #save the file with .mp3 extension
playsound('demo.mp3') #to play it
os.remove('demo.mp3')
Here is Male's and Female's voices function created by myself.
Just define a file name and save it.
Now you can import it into another file and reuse it again and again.
pip install pyttsx3
import pyttsx3
def femaleVoice(text):
print("Program : "+text)
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[-1].id)
engine.say(text)
engine.runAndWait()
def maleVoice(text):
print("Program : "+text)
pyttsx3.speak(text)
femaleVoice("There we go.")#Text
maleVoice("There we go.")
If you want access to a ton of voices. We have over 500.
Here's a snippet
python
import apiaudio
import os
apiaudio.api_key = os.environ['APIKEY']
first_track = apiaudio.Orchestrator.create_audio(scriptText="Hello World my first audio track",
voice="Ryan",
soundTemplate="jakarta")
print(first_track)
You just need a FREE api key. Have a look at http://www.api.audio