Capturing TTS output in Python - 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.

Related

How to get an application's version on macOS?

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)

Sublime Text doesn't recognize my installed module?

Hi I'm a complete beginner at Python and Sublime Text, but I'm trying to follow a video tutorial online and I followed along by downloading Python3 and creating a Python3 Build System in Sublime Text and installing Requests from my Mac Terminal. My problem is when I go to try and import requests, requests is seen as a string type I guess, but definitely not a module type which is what was shown in the video tutorial. When I run Python3 in my Terminal and type import requests, it works! Idk why Sublime Text is showing "abc" and not "module" as the type. 2

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.

How can I make Python speak with mbrola?

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()

Text to Speech Library for Python using Windows 8.1 (SAPI)

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!")

Categories