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

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.

Related

No module named sublime

I'm trying to work on some old code that used a library I'm not very familiar with anymore, and am getting the 'No module named' error. I'm using sublime text editor on windows. I had edited some things in build to run c++ previously if that might effect it.
If the library in particular matters, it is youtube_dl
I have tried $pip install -upgrade youtube_dl but it hasn't changed anything.
The code that is throwing an error is import youtube_dl
I searched around on the internet, and I found an answer.
(Edited for clarity)
”Sublime is a module only available in Sublime Text embedded Python interpreters.
import sublime will only work from a plugin or inside the console, not on your system Python interpreter.”
The forum post is here.
Not sure if this will help, as I do not know if you are trying to import sublime, but this is literally all the info I could find.
Hopefully this helps!

Can't import a cynthonized file after successful compilation (Python3)

I want to speed up my python code so i tried to translate it in c thanks to cython. I followed the basics tutorials and other youtube videos and i finally could create a functions_cython.c file. But somehow i just can't import it. I tried to import it in my main file, i also tried in another file named 'testing.py' but I always receive errors saying that the module 'functions_cython' does not exist, while it actually is in the file. Do you have any idea why ? (i linked some images if that can help)
The problem was because I was using PyCharm's "community version" and this version (in opposition of the professional one) does not allow to import .c formats. I switched to VS Code.

Python 3 Pyperclip Installed but Module not Found

I'm trying to copy some text to clipboad in my python program, so I've installed pyperclip via pip command via Windows command line interface, it says everything is successfully installed, not a problem. However, when I import the thing into my project, I get
from tkinter import *
from tkinter import ttk
import pyperclip
import binascii
#my code...
...
ModuleNotFoundError: No module named 'pyperclip'
So I was like *** that, maybe it's broken, I found a little library that does exactly the same, called "clipboard". Exactly the same installation procedure - from the command line. Same successful installation. Same ModuleNotFoundError. So clearly something wrong on my side, but I have no idea what it is, no idea where to look and what to do. I just want to be able to copy some text to clipboard. Multiplatform. That's it.
It's Python 3.8, Windows 10
pyperclip-1.8.0
pip-20.2.2
If I need to show you some logs or tell you something about my installation, please tell me what exactly to do and where to find information you may need. I'm good with instructions, but I don't have much (any) experience rummaging through logs and python installation folders.
Similar posts have slightly different problems, I didn't find any clear solution or hints that I could understand. No reply seemed like a solution to me.
Anyway, I would really appreciate any help from the community. Being unable to simply copy something to clipboard is killing me, especially since it's the only thing I can't implement. And it's just one function for one button to copy one short piece of text. It's like being stuck at 99% loading, when everything is done, and you just can't write the final line of code, haha.
Pycharm uses a virtualenv for pycharm projects. Navigate through:
Pycharm >> File >> Settings(or press Ctrl+Alt+S on win) >> Project:Name >> Project Interpreter >> Click on the plus(+) symbol above the scroll bar and type in pyperclip and press install package.
And this will install pyperclip for your Pycharm IDE. Since pycharm uses a virtual env for its projects you can change it in the project interpreter section as well, and then the pyperclip you installed from the cmd using pip, will be available to be used on that global version of python(now used by your Pycharm too).
If you still have any errors or doubts, do let me know :D
Cheers

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

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

Categories