Text to speech sapi5 python 3.8.6 - python-3.x

Whenever I try to run my text to speech program in python 3.8.6
it gives me error
My Code
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
print(voices)
engine.setProperty('voices', voices[0].id)
engine.say("hello")
engine.runAndWait()
Error
Traceback (most recent call last):
File "C:/Users/Admin/PycharmProjects/automating_Practices/Chat_Bot_PRogram/Voice_chatbot.py", line 20, in <module>
voices = engine.getProperty('voices')
File "C:\Python\Python386\lib\site-packages\pyttsx3\engine.py", line 146, in getProperty
return self.proxy.getProperty(name)
File "C:\Python\Python386\lib\site-packages\pyttsx3\driver.py", line 173, in getProperty
return self._driver.getProperty(name)
File "C:\Python\Python386\lib\site-packages\pyttsx3\drivers\sapi5.py", line 88, in getProperty
return [self._toVoice(attr) for attr in self._tts.GetVoices()]
File "C:\Python\Python386\lib\site-packages\pyttsx3\drivers\sapi5.py", line 88, in <listcomp>
return [self._toVoice(attr) for attr in self._tts.GetVoices()]
File "C:\Python\Python386\lib\site-packages\pyttsx3\drivers\sapi5.py", line 77, in _toVoice
return Voice(attr.Id, attr.GetDescription())
_ctypes.COMError: (-2147200966, None, (None, None, None, 0, None))
Please can anyone help me with this

Related

Problem starting Telegram bot with pyrogram

Hi i am receiving an error starting a bot with nothing on it yet
I am using Pyrogram (2.0.97) and Python (3.9.6)
I didn't developed more code for this bot yet, but i want to use this library (pyrogram) and not other library, because of this decorators that has on this library
Here is the simple code
from pyrogram import Client, filters
from pyrogram.types import Message
from pyrogram.types import (
InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup
)
TELEGRAM_API_ID = "22284blablabla"
TELEGRAM_API_HASH = "186a3759fc29f394bad2700cc29ecblablabla"
TELEGRAM_BOT_TOKEN = "blablablablabla"
app = Client(
'SegBot',
api_id=TELEGRAM_API_ID,
api_hash=TELEGRAM_API_HASH,
bot_token=TELEGRAM_BOT_TOKEN
)
#app.on_message(filters.private)
async def hello(client, message):
await message.reply("Hello from Pyrogram!")
print('running!!!')
app.run()
And the error is:
running!!!
Traceback (most recent call last):
File "G:\Drives compartilhados\SEG FIS\API\TELEGRAM BOT TEST\bot_test.py", line 151, in <module>
app.run()
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\methods\utilities\run.py", line 84, in run
self.start()
return loop.run_until_complete(coroutine)
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\methods\utilities\start.py", line 58, in start
is_authorized = await self.connect()
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\methods\auth\connect.py", line 40, in connect
await self.load_session()
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\client.py", line 586, in load_session
await Auth(
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\session\auth.py", line 254, in create
raise e
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\session\auth.py", line 89, in create
res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\session\auth.py", line 67, in invoke
return self.unpack(response)
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\session\auth.py", line 60, in unpack
return TLObject.read(b)
File "C:\Users\roberto.lins\AppData\Roaming\Python\Python39\site-packages\pyrogram\raw\core\tl_object.py", line 33, in read
return cast(TLObject, objects[int.from_bytes(b.read(4), "little")]).read(b, *args)
KeyError: 0
Any help, please?

Pyttsx3 Voice KeyError: 'sapi5'

Getting unknown voice id error. I tried with ( Pyttsx3 2.6 and python 3.6 ), ( pyttsx3==2.9 & python 3.10)
Traceback (most recent call last):
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "E:\anaconda3\envs\dummy\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Dnyanesh/PycharmProjects/dummy/main.py", line 5, in <module>
engine = pyttsx3.init()
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\driver.py", line 77, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
return SAPI5Driver(proxy)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 41, in __init__
self.setProperty('voice', self.getProperty('voice'))
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 82, in setProperty
token = self._tokenFromId(value)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 66, in _tokenFromId
raise ValueError('unknown voice id %s', id_)
ValueError: ('unknown voice id %s', 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices\\Tokens\\MSTTS_V110_enUS_DavidM')

what is the portable equivalent to linux`s signal.siginterrupt in python?

I have this Linux centric code that I would like to get to run on Windows, too:
class SignalObject:
MAX_TERMINATE_CALLED = 3
def __init__(self, shutdown_event):
self.terminate_called = 0
self.shutdown_event = shutdown_event
def default_signal_handler(signal_object, exception_class, signal_num, current_stack_frame):
signal_object.terminate_called += 1
signal_object.shutdown_event.set()
if signal_object.terminate_called >= signal_object.MAX_TERMINATE_CALLED:
raise exception_class()
def init_signal(signal_num, signal_object, exception_class, handler):
handler = functools.partial(handler, signal_object, exception_class)
signal.signal(signal_num, handler)
signal.siginterrupt(signal_num, False)
def init_signals(shutdown_event, int_handler, term_handler):
signal_object = SignalObject(shutdown_event)
init_signal(signal.SIGINT, signal_object, KeyboardInterrupt, int_handler)
init_signal(signal.SIGTERM, signal_object, TerminateInterrupt, term_handler)
return signal_object
Specifically, it bombs out on signal.siginterrupt(signal_num, False) and gives me this traceback:
ERROR:root: 0:00.000 MAIN Exception: module 'signal' has no attribute 'siginterrupt'
Traceback (most recent call last):
File "C:/Users/Documents/GitHub/magnetfeld-kabel/util/bin/magnetic_cable_interactive.py", line 186, in main
init_signals(main_ctx.shutdown_event, default_signal_handler, default_signal_handler)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\mptools-0.2.0-py3.7.egg\mptools\_mptools.py", line 115, in init_signals
init_signal(signal.SIGINT, signal_object, KeyboardInterrupt, int_handler)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\mptools-0.2.0-py3.7.egg\mptools\_mptools.py", line 110, in init_signal
signal.siginterrupt(signal_num, False)
AttributeError: module 'signal' has no attribute 'siginterrupt'
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2019.3.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Documents/GitHub/magnetfeld-kabel/util/bin/magnetic_cable_interactive.py", line 221, in <module>
main(die_in_secs)
File "C:/Users/Documents/GitHub/magnetfeld-kabel/util/bin/magnetic_cable_interactive.py", line 186, in main
init_signals(main_ctx.shutdown_event, default_signal_handler, default_signal_handler)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\mptools-0.2.0-py3.7.egg\mptools\_mptools.py", line 115, in init_signals
init_signal(signal.SIGINT, signal_object, KeyboardInterrupt, int_handler)
File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\mptools-0.2.0-py3.7.egg\mptools\_mptools.py", line 110, in init_signal
signal.siginterrupt(signal_num, False)
AttributeError: module 'signal' has no attribute 'siginterrupt'
How can I change that to run on both Windows and Linux? I googled for equivalents and found nothing.

Error while creating a service using nameko for Pysnmp get_request--Attempted "nameko_entrypoints" operation on ASN.1 schema object

I am new to pysnmp and nameko. I have been assignment a work to create a service in nameko framework to perform snmp get_request using pysnmp library.
Below is the code i have tried
from pysnmp.hlapi import *
from nameko.rpc import rpc
class GreetingService(object):
name = "greeting_service"
#rpc
def getFunc(oid):
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget(('snmp.live.gambitcommunications.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', oid, 0)))
)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
if __name__ == "__main__":
getFunc('sysName')
when i try to start the service using terminal with the following command
$ nameko run helloworld
I get the following error message.
syed#syed-ThinkPad-E480:~/Pysnmp$ nameko run helloworld
Traceback (most recent call last):
File "/home/syed/.local/bin/nameko", line 11, in <module>
sys.exit(main())
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/main.py", line 112, in main
args.main(args)
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/commands.py", line 110, in main
main(args)
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/run.py", line 181, in main
import_service(path)
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/run.py", line 71, in import_service
if inspect.getmembers(potential_service, is_entrypoint):
File "/usr/lib/python3.7/inspect.py", line 354, in getmembers
if not predicate or predicate(value):
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/run.py", line 35, in is_entrypoint
return hasattr(method, ENTRYPOINT_EXTENSIONS_ATTR)
File "/home/syed/.local/lib/python3.7/site-packages/pyasn1/type/base.py", line 221, in __getattr__
raise error.PyAsn1Error('Attempted "%s" operation on ASN.1 schema object' % attr)
pyasn1.error.PyAsn1Error: Attempted "nameko_entrypoints" operation on ASN.1 schema object
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "/home/syed/.local/bin/nameko", line 11, in <module>
sys.exit(main())
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/main.py", line 112, in main
args.main(args)
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/commands.py", line 110, in main
main(args)
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/run.py", line 181, in main
import_service(path)
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/run.py", line 71, in import_service
if inspect.getmembers(potential_service, is_entrypoint):
File "/usr/lib/python3.7/inspect.py", line 354, in getmembers
if not predicate or predicate(value):
File "/home/syed/.local/lib/python3.7/site-packages/nameko/cli/run.py", line 35, in is_entrypoint
return hasattr(method, ENTRYPOINT_EXTENSIONS_ATTR)
File "/home/syed/.local/lib/python3.7/site-packages/pyasn1/type/base.py", line 221, in __getattr__
raise error.PyAsn1Error('Attempted "%s" operation on ASN.1 schema object' % attr)
pyasn1.error.PyAsn1Error: Attempted "nameko_entrypoints" operation on ASN.1 schema object
Please help me out to understand weather what i have tried is correct way or else it is wrong.. If so how to rectify the mistake.
Any help will be appreciable.
Thanks in advance
It has something to do with the way how nameko hooks up your code...
It seems to try looking up nameko_entrypoints attribute at all objects it can find in your module eventually running into ASN.1 schema objects (which are sacred and should not be used for anything other than blueprinting purposes).
My suggestion would be to replace from pysnmp.hlapi import * with specific imports of pysnmp classes/functions you are using in your code. That should hopefully hide fragile pieces out of nameko's sight.

Python3.5 Xlib error anyone met the same?

I am trying to install pyautogui. And it have some error shown as below:
File "<pyshell#2>", line 1, in <module>
display = Display()
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/lib/python3.5/site-packages/Xlib/protocol/display.py", line 160, in __init__
raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n'
then I googled and found some experts had found some bugs:
https://github.com/LiuLang/python3-xlib/issues/6
https://github.com/LiuLang/python3-xlib/issues/7
so they solved it by change the code of xauth.py in Xlib.
While when I followed it, it raised another error shown as below:
File "<pyshell#2>", line 1, in <module>
display = Display()
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/lib/python3.5/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/lib/python3.5/site-packages/Xlib/protocol/display.py", line 92, in __init__
name, host, displayno)
File "/usr/lib/python3.5/site-packages/Xlib/support/connect.py", line 101, in get_auth
return mod.get_auth(sock, dname, host, dno)
File "/usr/lib/python3.5/site-packages/Xlib/support/unix_connect.py", line 124, in new_get_auth
return au.get_best_auth(family, addr, dno)
File "/usr/lib/python3.5/site-packages/Xlib/xauth.py", line 112, in get_best_auth
address = address.encode()
AttributeError: 'bytes' object has no attribute 'encode'
have you ever met the similar issue? or it is because of my system have something wrong?
(edited later)
I just tried to do everything in python2.7.12 I had met the below error msg:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
display = Display()
File "/usr/lib/python2.7/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/lib/python2.7/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/lib/python2.7/site-packages/Xlib/protocol/display.py", line 92, in __init__
name, host, displayno)
File "/usr/lib/python2.7/site-packages/Xlib/support/connect.py", line 101, in get_auth
return mod.get_auth(sock, dname, host, dno)
File "/usr/lib/python2.7/site-packages/Xlib/support/unix_connect.py", line 121, in new_get_auth
au = xauth.Xauthority()
File "/usr/lib/python2.7/site-packages/Xlib/xauth.py", line 47, in __init__
raise error.XauthError('~/.Xauthority: %s' % err)
XauthError: ~/.Xauthority: [Errno 2] No such file or directory: '/home/rnie/.Xauthority'
Have you met this problem? the .Xauthority should be under my user home directory by default, right? I can not find it by checking "cat ~/.Xauthority". It says no such a file:(

Resources