Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
text to speech
#1
Fellow Python Users,

I want to put several words in a list. Then tell Python to say the word.

I did some searches on text to speech. I found 2 lines of code which do not work. Does anyone have an idea of what is wrong?

#This is a way to use text to speech from a windows PC
from win32com.client import Dispatch
speak = Dispatch("SAPI.SpVoice")
speak.Speak("Ciao")
#This is a way to use text to speech if you have windows 10 and Python 3
import win32com.client as wincl
speak = wincl.Dispatch("SAPI.SpVoice")
speak.Speak("This is the pc voice speaking")
The error message I get is: C:\Users\Joe\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'C:/Users/Joe/PycharmProjects/myproj.py/ran.py': [Errno 2] No such file or directory

I have no idea what the file ran.py is.
Reply
#2
You done a double name .py extension save,can not have both myproj.py and ran.py.
Create and run your first Python project
Reply
#3
I couldn't find the double name extension save so I uninstalled Python and Pycharm, installed them again and started a new file. Now the error message is that there is no 'win32com' module. I have Windows 10. Shouldn't I have that module?

Traceback (most recent call last):
File "C:/Users/Joe/PycharmProjects/Myproject/texttospeech.py", line 2, in <module>
from win32com.client import Dispatch
ModuleNotFoundError: No module named 'win32com'

Process finished with exit code 1
Reply
#4
(Jun-28-2020, 06:18 PM)Heyjoe Wrote: I have Windows 10. Shouldn't I have that module?
No most install pywin32.
pip install pywin32
Reply
#5
I did the following installation as instructed by snippsat.

pip install pywin32

It installed successfully. It told me that the installation was an older version, so I did the installation of the newer version.

I ran the following two codes.

#This is a way to use text to speech if you have python 3 and windows 10
import win32com.client as wincl
speak = wincl.Dispatch("SAPI.SpVoice")
speak.Speak("This is the pc voice speaking")
#This is a way to use text to speech from a windows PC
from win32com.client import Dispatch
speak = Dispatch("SAPI.SpVoice")
speak.Speak("Ciao")
Both codes gave me an error saying that win32 was not installed.


I tried to install pywin32 again and it told me it was already installed.

Anyone have an idea of what I did wrong?
Reply
#6
Have you tried espeak? It't works well on linux. Haven't tried on windows.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#7
As you use PyCharm most choose right interpreter.
Configure a Python interpreter PyCharm
So for you this is the path.
C:\Users\Joe\AppData\Local\Programs\Python\Python38-32\python.exe
Also look here,make sure that python and pip command work from cmd.

Learn to run and install from command line,it's a important part of basic programming skill.
Quick example in cmder,same in cmd.
C:\
λ cd code

# Test python 
C:\code
λ python -V
Python 3.8.3

# Test pip
C:\Code
λ pip -V
pip 20.1.1 from c:\python38\lib\site-packages\pip (python 3.8)

# Install
C:\code
λ pip install pywin32
Requirement already satisfied: pywin32 in c:\python38\lib\site-packages (228)

# Look at code,use <more> in cmd
C:\code
λ cat ciao.py
from win32com.client import Dispatch

speak = Dispatch("SAPI.SpVoice")
speak.Speak("Ciao")

# Run code and it works
C:\code
λ python ciao.py
Reply
#8
Snippsat

I tried to run the C prompt commands that you gave me. I believe the output is the same as yours until I tried to run cat ciao.py. As you can see this resulted in an error. I changed the directory to where this file is located and it also resulted in an error. So I understand the first 3 commands, but I don't understand cat ciao.py.

C:\Users\Joe>cd\

C:\>python -V
Python 3.8.3

C:\>pip -V
pip 20.1.1 from c:\users\joe\appdata\local\programs\python\python38-32\lib\site-packages\pip (python 3.8)

C:\>pip install pywin32
Requirement already satisfied: pywin32 in c:\users\joe\appdata\local\programs\python\python38-32\lib\site-packages (228)
C:\>cat ciao.py
'cat' is not recognized as an internal or external command,
operable program or batch file.

C:\>cd\users\joe\pycharmprojects\myproject

C:\Users\Joe\PycharmProjects\Myproject>cat ciao.py
'cat' is not recognized as an internal or external command,
operable program or batch
Reply
#9
(Jun-30-2020, 09:44 PM)Heyjoe Wrote: but I don't understand cat ciao.py.
Look one more time what i write Wink
snippsat Wrote:# Look at code,use <more> in cmd
So it's like this in cmd.
C:\>cd code

# look at file
C:\code>more ciao.py
from win32com.client import Dispatch

speak = Dispatch("SAPI.SpVoice")
speak.Speak("Ciao")

# Run file
C:\code>python ciao.py 

C:\code>
cat is Linux command,so when i use cmder can use cat as it feel much more natural than the cmd commands for me.
Reply
#10
The file ciao is in the directory \Users\Joe\PycharmProjects\Myproject So I did the following 2 command prompts commands from that directory.

C:\Users\Joe\PycharmProjects\Myproject>more ciao.py

#This is a way to use text to speech from a windows PC
from win32com.client import Dispatch
speak = Dispatch("SAPI.SpVoice")
speak.Speak("Ciao")

C:\Users\Joe\PycharmProjects\Myproject>python ciao.py

So for the first command it showed what my code is.

And the second command did work & I heard the word "ciao".

I am wondering if it has to do if how I have my interpreter set up in Pycharm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Controlling text-to-speech pauses with pyttsx3 pmac1300 4 4,322 Mar-14-2022, 06:47 AM
Last Post: Coricoco_fr
  Speech Recognition with timestamps DeanAseraf1 3 6,500 Jun-27-2021, 06:58 PM
Last Post: gh_ad
  Continous Speech Recognition dell91 0 1,807 Oct-29-2020, 10:51 AM
Last Post: dell91
  How to Split Output Audio on Text to Speech Code Base12 2 6,785 Aug-29-2020, 03:23 AM
Last Post: Base12
  Googles Text to speech justindiaz7474 0 1,629 May-06-2020, 02:04 AM
Last Post: justindiaz7474
  Simulation of Text to speech (without using mic) to Voice recognition suported hardwa Helloworld20 2 2,192 Apr-08-2020, 02:13 AM
Last Post: Helloworld20
  Python Speech Engines? Robo_Pi 2 2,059 Mar-12-2020, 02:46 PM
Last Post: Robo_Pi
  Speech Recognition Ash23733 1 8,529 Dec-12-2018, 10:00 PM
Last Post: nilamo
  Speech (audio file, wav) to Text - Broken pipe Shobha 1 3,713 Nov-27-2018, 12:41 PM
Last Post: Larz60+
  Need Help With Text to Speech App Lethe 0 1,955 Oct-24-2018, 10:03 PM
Last Post: Lethe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020