Lovish Thakral
Lovish Thakral

Reputation: 1

Error occuring while using win32 in vs code (in python )

I am trying to convert text to speech in Python 3.10.2 using the code:

import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Hello, it works!")

But there is continuously occuring an error:

Traceback (most recent call last):   File "d:\Program\Python programing\tempCodeRunnerFile.py", line 1, in <module>
    import win32com.client   File "C:\Users\ASUS\AppData\Roaming\Python\Python310\site-packages\win32com\client\__init__.py",
line 10, in <module>
    from . import dynamic   File "C:\Users\ASUS\AppData\Roaming\Python\Python310\site-packages\win32com\client\dynamic.py",
line 24, in <module>
    from . import build   File "C:\Users\ASUS\AppData\Roaming\Python\Python310\site-packages\win32com\client\build.py",
line 638, in <module>
    valid_identifier_chars = string.ascii_letters + string.digits + "_" AttributeError: module 'string' has no attribute 'ascii_letters'

Upvotes: 0

Views: 447

Answers (1)

Mohamed Hamada
Mohamed Hamada

Reputation: 31

you wrote two lines of code in the same line Try this

import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Hello, it works!")

or try to put a semicolon after the first line of code Try this

import win32com.client; speaker =win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("Hello, it works!")

either way should work

Upvotes: 1

Related Questions