I'm trying to create a simple program that will relay what I type as synthesized speech. I've tried pyttsx, it has been known to not work with python 3.x and it sure doesn't. I also tried using speech, but it interfered with the speech_recognition Library I'm using. I don't have any code to show since I don't even have a Library for it yet.
Running Python 3.4.2 32-bit on Windows 8.1 64-bit
According to this POST, considering that you are targeting the Windows platform, the following will work:
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Hello, it works!")
Related
I am writing a simple script using python to be used on macOS BigSur. I was wondering if there is a way to find the version of an application using python. I know it's possible on Windows using PyWin32 library, however, I could not find anything for MacOS.
Thanks #sudden_appearance for the approach
import os
stream = os.popen('mdls -raw -name kMDItemVersion /Applications/Firefox.app')
targetVer = stream.read()
print(targetVer)
I have a working code on Windows which, after a bunch of many other steps, uses Audacity to de-noise the received audio file. I had been using the following code on Windows to transfer control to perform a set of actions:
import pywinauto
from pywinauto import application
def noiseReduce(filename):
app = application.Application()
app = app.connect(path=r'/Applications/Audacity')
app.captcha20170411_202241.menu_select('File->Import->Audio')
app.Selectoneormoreaudiofiles.Edit.SetText(filename + '.wav')
I ported this code to my Mac and installed the necessary Py modules like pywinauto. However, I am getting this error:
File "/Users/gautam/PycharmProjects/project/Capture.py", line 20, in <module>
from pywinauto import application
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pywinauto/application.py", line 75, in <module>
import win32process
ImportError: No module named 'win32process'
On trying to pip install win32process, I am getting an error:
Could not find a version that satisfies the requirement win32process
(from versions: ) No matching distribution found for win32process
Is there a way to resolve this or another alternative to transfer control to Audacity and perform actions on it?
Currently pywinauto doesn't support Apple Accessibility API and shouldn't work on MacOS.
Unfortunately there is no good cross-platform GUI automation tool (using accessibility text-based approach) in the open source field. The only one is LDTP (Linux Desktop Testing Project) and API-compatible Cobra (on Windows) and pyatom (MacOS). Fortunately pyatom is a standalone self-contained library as well. My students were able to automate few apps using pyatom. You may consider using it for now.
P.S. We're trying to make pywinauto cross-platform (with real seamless integration), but MacOS backend implementation is on the very early development stage for now. I expect to introduce Linux AT-SPI support earlier than Apple Accessibility API one.
When I do Python UDF with Pig, how do we know which version of Python it is using? Is it possible to use a specific version of Python?
Specifically my problem is in my UDF, I need to use a function in math module math.erf() which is newly introduced in Python version 2.7. I have Python 2.7 installed on my machine and standalone Python program runs fine but when I run it in Pig as Python UDF, I got this:
AttributeError: type object 'org.python.modules.math' has no attribute 'erf'
My guess is Jython is using some pre-2.7 version of Python?
Thanks for your help!
To get the version you are using you can do this:
myUDFS.py
#!/usr/bin/python
import sys
#outputSchema('bar: chararray')
def my_func(foo):
print sys.version
return foo
If you run the script locally then the version will be printed directly to stdout. To see the output of sys.version when you run it remotely you'll have to check the logs on the job tracker.
However, you are right about Jython being pre-2.7 (kind of). The current stable version of Jython right now is 2.5.3, so this is the version that Pig is using. There is a beta version of 2.7.
I am looking to simulate keystrokes in python 3.2 in windows 7 to be sent to a GUI.I have python win32 module installed on my pc.The order is alt+t+r+name+enter.What would be the best way of sending these keystrokes to the active window?any sample code would be of a great help.
Thanking you.
(I have seen some module called sendkeys but can that be used with pywin32?i am not allowed to install any other modules)
I know this may not be perfect. We have a testing application using python 2.7. We leverage the windows scripting host to send keys. I have not had time to port anything over to python 3, but this might get you in the right direction. It should be pretty similar.
import win32api
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.Run("app")
win32api.Sleep(100)
shell.AppActivate("myApp")
win32api.Sleep(100)
shell.SendKeys("%")
win32api.Sleep(500)
shell.SendKeys("t")
win32api.Sleep(500)
shell.SendKeys("r")
win32api.Sleep(500)
shell.SendKeys("name")
win32api.Sleep(500)
shell.SendKeys("{ENTER}")
win32api.Sleep(2500)
Here is a list of the send key commands for Windows Scripting Host.
Update
This uses pywin32. It is installed by default in the ActiveState version of python (which is the one I am using). I am not sure, but I do not believe, that it is installed by default in the plain vanilla version of python.
What I'm trying to achieve is to save a text to speech output from Python to an audiofile.
Well the only constraint is Python version 2.7 (would be cool if it runs on Windows and ubuntu, but not necessary). I found pyttsx and managed to have a text read but I can't capture it because there is no method like in pyTTS SpeakToMemory. Well pyTTS is just available for Python 2.5. I can't use that either.
How can I make a text to speech and save it in an audio file with python 2.7?
How to create audio from text with google text to speech API
First install gtts from cmd
pip install gtts
from gtts import gTTS
tts = gTTS("Hello","en")
tts.save("hello.mp3")
and you're done.
Your question implies it's ok if this is a Mac OS X only solution? If so, then you can modify the Mac OS X driver in pyttsx (pyttsx/drivers/nsss.py) and give it the ability to call the startSpeakingString:toURL: method on the NSSpeechSynthesizer class:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSpeechSynthesizer_Class/Reference/Reference.html
This will save synthesized text to a file.