How to convert text to speech in python 3.5 on windows 10? - python-3.x

I tried espeak but didn't succeed and some functionalities only supported in python 2.

For offline use in Windows, use SAPI directly.
You can use SpVoice.
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Jumpman Jumpman Jumpman Them boys up to something!")

Have you tried using Google Text-to-Speech via gTTS?
The syntax for using it in Python 3.x is as follows:
from gtts import gTTS
my_tts = "Text you want to process"
tts = gTTS(text=my_tts, lang='en')
tts.save("Absolute/path/to/file.mp3")
Here is the github repo of gTTS.

Related

Speech to text Conversion Using Python

I am new to python and want to convert speech to text using python libraries.But not using APIs.Basically,I want my code to run without internet too.Which library I should use?I have learned SpeechRecognition is the simplest one but I see in every use case it makes use of an API.Please suggest how should I proceed.
You can try using pyttsx3 module. It stands for Python Text To Speech version 3.
you can check out my GitHub repo to learn about the use of speech recognition and pyttsx3.
https://github.com/shuvampaul2005/J.A.R.V.I.S

What are Python3 libraries which replace "from scikits.audiolab import Format, Sndfile"

Hope you'll are doing good. I am new to python. I am trying to use audio.scikits library in python3 verion. I have a working code version in 2.7(with audio.scikits) . While I am running with python3 version I am getting the Import Error: No Module Named 'Version' error. I get to know that python3 is not anymore supporting audio.scikits(If I am not wrong). Can anyone suggest me replacing library for audio.scikits where I can use all the functionalities like audio.scikits do OR any other solution which might helps me. Thanks in advance.
2.7 Version Code :
from scikits.audiolab import Format, Sndfile
from scipy.signal import firwin, lfilter
array = np.array(all)
fmt = Format('flac', 'pcm16')
nchannels = 1
cd, FileNameTmp = mkstemp('TmpSpeechFile.wav')
# making the file .flac
afile = Sndfile(FileNameTmp, 'w', fmt, nchannels, RawRate)
#writing in the file
afile.write_frames(array)
SendSpeech(FileNameTmp)
To check entire code please visit :Google Asterisk Reference Code(modifying based on this code)
I want to modify this code with python3 supported libraries. Here I am doing this for Asterisk-Microsoft-Speech To Text SDK.
Firstly the link code you paste is Asterisk-Google-Speech-Recognition, it's not the Microsoft-Speech-To-Text, if you want get a sample about Microsoft-Speech-To-Text you could refer to the official doc:Recognize speech from an audio file.
And about your problem you said, yes it's not completely compatible, in the github issue there is a solution for it, you could refer to this comment.

Using Dispatch from win32com.client 'SAPI.Spvoice'

I'm trying to use Python code to change WIN10 text-to-speech voice from Windows Default to English.
There are mentions of using SetVoice commands with SAPI.Spvoice, but cannot find the expample
from win32com.client import Dispatch
Windows_Speak = Dispatch('SAPI.Spvoice')
Windows_Speak.Speak('Tomato')
The above code would use the Windows default language settings, but I need to be able to change languages using in-Python commands. Any ideas?
Try this:
from win32com.client import Dispatch
Windows_Speak = Dispatch('SAPI.Spvoice')
Windows_Speak.Voice = speak.GetVoices().Item(2)
Windows_Speak.Rate = 3
print(speak.GetVoices().Item(2).GetDescription()) #just to see what voice is used
Windows_Speak.Speak('Tomato')
Play around if the voice id
One alternative could be using 'pyttsx3.
If you are trying to change voice from your Window's default one, then you can use try this:
engine = pyttsx3.init('sapi5')
#with given method you will get the list of voices available
voices = engine.getProperty('voices')
#in engine I am setting 0th indexed voice as my custom
engine.setProperty('voice', voices[0].id)

Is there a way to programmatically clear the terminal across platforms in Python 3?

Long-time lurker, first time asker.
Is there a way to automatically clear the terminal in Python 3 regardless of what platform the app is being used in?
I've come across the following (from this answer) which utilises ANSI escape codes:
import sys
sys.stderr.write("\x1b[2J\x1b[H")
But for it to work cross-platform it requires the colorama module which appears to only work on python 2.7.
For context I'm learning Python by building a game of battleships, but after each guess I want to be able to clear the screen and re-print the board.
Any help is appreciated!
Cheers
I use a single snippet for all the platforms:
import subprocess
clear = lambda: subprocess.call('cls' if os.name=='nt' else 'clear')
clear()
Same idea but with a spoon of syntactic sugar:
import subprocess
clear = lambda: subprocess.call('cls||clear', shell=True)
clear()
I know of this method
import os
clear = lambda: os.system('cls')
clear()
I'm not sure if it works with other platforms, but it's working in windows python 3.x
import os
clear = lambda: os.system('clear')
clear()
That might work for linux and OS X, but I can't test.

Cross-platform screenshot in Python 3

There are quite a few questions like this one, but none of them seem to be both cross-platform and specifically for Python 3, and I'm struggling to find a reliable solution.
How can I take a cross-platform screenshot in Python 3?
My current solution has been to use the ImageGrab function from the PIL library, like so:
from PIL import ImageGrab
image = ImageGrab.grab()
You can use platform.system() to find the current OS, and then use a different solution depending on the operating system:
import platform
if platform.system()=="Windows":
...
elif platform.system()=="Darwin": #Mac
...
elif plarform.system()=="Linux":
...
You can use PrtSc Library.
Command : pip3 install PrtSc
Code :
import PrtSc.PrtSc as Screen
screen=Screen.PrtSc(True,"file.png")

Resources