How can I make Python speak with mbrola? - python

I need to create a Python program, which will speak the numbers chosen randomly. Like, Python gives me number 11, and with mbrola, it says "eleven". It's very simple, I've created almost everything, but the only thing I need is - make Python speaks it using mbrola!
Please, could you give me some examples?

There is a python module called pyttsx which speaks things. You can install it by using pip install pyttsx and then use it as such
import pyttsx as tts
engine = tts.init()
engine.say('Eleven')
engine.runAndWait()

Related

Erwin API with Python

I am trying to get clear concept on how to get the Erwin generated DDL objects with python ? I am aware Erwin API needs to be used. What i am looking if what Python Module and what API needs to used and how to use them ? I would be thankful for some example !
Here is a start:
import win32com.client
ERwin = win32com.client.Dispatch("erwin9.SCAPI")
I haven't been able to browse the scapi dll so what I know is from trial and error. Erwin publishes VB code that works, but it is not straightforward to convert.
Install pywin32 (run the below from pip folder e.g. c:\Program Files\Python37\Scripts)
python -m pip install pywin32
python pywin32_postinstall.py -install
Sample script to extract DDL using Erwin's Forward Engineer functionality (change paths accordingly):
import win32com.client
api = win32com.client.Dispatch("erwin9.SCAPI")
unit = api.PersistenceUnits.Add("c:/models/data_model.erwin", "RDO=Yes")
unit.FEModel_DDL("c:/scripts/ddl_script.sql")
For the above to work, Erwin application should be running (probably).

How to use gTTS (google text to speech) in visual studio code?

I want to use the google text to speech(gTTS) in my visual studio code project. I need help with:
a) downloading it
b)using it in VS Code
c) running it in VS Code
I've been really confused on trying to use this module and other modules in VS Code.
Thanks for helping in advance, if anything is unclear leave a comment and i'll update the question!
If I understand your question correctly, then you just need to install the gTTS module using pip install gTTS from the terminal (to this you need to have python set to path).
Demonstration of install of gTTS in VS code
To open the terminal in VS code you can use the keyboard shortcut Ctrl + Shift + P to bring up the command pallet, where in you can type terminal and then you will see a option to open the terminal in VS code.
Opening the terminal in VS code
Then you will be able to use the module in your python files like this:
>>> from gtts import gTTS
>>> tts = gTTS('hello')
>>> tts.save('hello.mp3')
This piece will take the string and save it as a mp3 file of the gTTS voice from the text in line 2.
Demonstration of the code-example in VS code
For more information go to the official site for gTTS:
https://pypi.org/project/gTTS/
For using python modules in VS code or any other editor is just the matter of installing them using the guidance on the module's website (sometimes one needs to restart the editor before one can use the module). Then to use the module one just needs to import it in the beginning og the file, that the module needs to be used.

J meter with Python : how to import the packages

Iam new bee to the jmeter
My code is working in the Python 2.7 with importing additional packages Dateutil, parser .
Problme : But when I am trying to run same code in the J Meter-JSR-223 PreProcessors , an error saying No module named dateutil in.
So , I have tried another approach to use Jython .
Installed the Jython ( downloaded the dateutil) and provide the packages reference under
import sys
sys.path.append('C:/Jython27/Lib/site-packages')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
sys.path.append('C:/Jython27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
Now packages error is gone but string syntax error is present .
java.sql.Date' object has no attribute .
I believe dateutil package can be picked up from CPython as it doesn't require any extra wrappers for Java.
Install dateutil normally using pip like:
pip install python-dateutil
Add site-packages folder of Python (not Jython) installation to sys.path like:
sys.path.append("C:\Python27\Lib\site-packages")
That's it, now you should be able to use dateutil module functions from the JSR223 Test Elements:
Be aware that invoking Python scripts via Jython interpreter is not the best idea from performance perspective and if you're about to invoke your Python code only limited number of times and/or with a single thread - it might be better to go for the OS Process Sampler.
If you plan to use the Python code to create the main load - consider using Locust tool instead of JMeter. If you don't want to change JMeter a good approach would be rewriting your Python code in Groovy - it will be way better from the performance perspective.
hi please find follwing
import sys
sys.path.append('C:/Python27/Lib/site-packages')
sys.path.append('C:/Python27/Lib/site-packages/python_dateutil-2.4.2-py2.7/dateutil')
from dateutil.parser import *
sourceDateTimeOfEvent = ""
dateTimeOfEvent = ""
a=parse('2016-07-01 13:00:00')
sourceDateTimeOfEvent = a.isoformat()+"+05:30Z"
dateTimeOfEvent = a.isoformat()+ "Z"
vars.put("sourceDateTimeOfEvent", sourceDateTimeOfEvent)
vars.put("dateTimeOfEvent", dateTimeOfEvent)
This sourceDateTimeOfEvent and dateTimeOfEvent considered as two variables and passed it to the json file

How do i use import to put pywws into python 3?

I have a weather station and i need to write a program which can take the instrument readings and save them in a text file. I decided to try and use pywws to retrieve the data but i cannot import the module into python to use its commands. I am doing this on a raspberry pi model B and i am using python 3 and the latest version of pywws. When i try to use import pywws it says that it does not exist. I am using a USB wireless weather forecaster from maplin and so far i have been using this tutorial to set it up: http://www.weather.dragontail.co.uk/index.php?page=pywws_ini
I fixed this problem, turns out that pywws does not work with python 3, it only works with python 2. I booted up python 2 and typed "import pywws" and it worked fine.
pywws definitely does work with python 3, as long as you install it correctly. Python 2 to Python 3 translation is done by the setup.py script during installation.

Python Sound ("Bell")

I'd like to have a python program alert me when it has completed its task by making a beep noise. Currently, I use import os and then use a command line speech program to say "Process complete". I much rather it be a simple "bell."
I know that there's a function that can be used in Cocoa apps, NSBeep, but I don't think that has much anything to do with this.
I've also tried
print(\a)
but that didn't work.
I'm using a Mac, if you couldn't tell by my Cocoa comment, so that may help.
Have you tried :
import sys
sys.stdout.write('\a')
sys.stdout.flush()
That works for me here on Mac OS 10.5
Actually, I think your original attempt works also with a little modification:
print('\a')
(You just need the single quotes around the character sequence).
If you have PyObjC (the Python - Objective-C bridge) installed or are running on OS X 10.5's system python (which ships with PyObjC), you can do
from AppKit import NSBeep
NSBeep()
to play the system alert.
I tried the mixer from the pygame module, and it works fine. First install the module:
$ sudo apt-get install python-pygame
Then in the program, write this:
from pygame import mixer
mixer.init() #you must initialize the mixer
alert=mixer.Sound('bell.wav')
alert.play()
With pygame you have a lot of customization options, which you may additionally experiment with.
I had to turn off the "Silence terminal bell" option in my active Terminal Profile in iTerm for print('\a') to work. It seemed to work fine by default in Terminal.
You can also use the Mac module Carbon.Snd to play the system beep:
>>> import Carbon.Snd
>>> Carbon.Snd.SysBeep(1)
>>>
The Carbon modules don't have any documentation, so I had to use help(Carbon.Snd) to see what functions were available. It seems to be a direct interface onto Carbon, so the docs on Apple Developer Connection probably help.
Building on Barry Wark's answer...
NSBeep() from AppKit works fine, but also makes the terminal/app icon in the taskbar jump.
A few extra lines with NSSound() avoids that and gives the opportunity to use another sound:
from AppKit import NSSound
#prepare sound:
sound = NSSound.alloc()
sound.initWithContentsOfFile_byReference_('/System/Library/Sounds/Ping.aiff', True)
#rewind and play whenever you need it:
sound.stop() #rewind
sound.play()
Standard sound files can be found via commandline locate /System/Library/Sounds/*.aiff
The file used by NSBeep() seems to be '/System/Library/Sounds/Funk.aiff'
By the way: there is a module for that. ;-)
Just install via pip:
pip3 install mac_alerts
run your sound:
from mac_alerts import alerts
alerts.play_error() # plays an error sound
Play sound worked for me. Install using pip
pip3 install playsound
To play sound
from playsound import playsound
playsound('beep.wav')
References:
Found the examples here
downloaded beep.wav from here

Categories