Reputation: 11
I am editing a part of conversation.py which is a part Jasper voice recognition software to add sound effects. The part of the code I am concerned with is init(). I am using code and trying to replicate self.speaker = speaker from mic.py
ORIGINAL CODE:
# -*- coding: utf-8-*-
import logging
from notifier import Notifier
from brain import Brain
class Conversation(object):
def __init__(self, persona, mic, profile):
self._logger = logging.getLogger(__name__)
self.persona = persona
self.mic = mic
self.profile = profile
self.brain = Brain(mic, profile)
self.notifier = Notifier(profile)
def handleForever(self):
"""
Delegates user input to the handling function when activated.
"""
self._logger.info("Starting to handle conversation with keyword '%s'.",
self.persona)
while True:
# Print notifications until empty
notifications = self.notifier.getAllNotifications()
for notif in notifications:
self._logger.info("Received notification: '%s'", str(notif))
self._logger.debug("Started listening for keyword '%s'",
self.persona)
threshold, transcribed = self.mic.passiveListen(self.persona)
self._logger.debug("Stopped listening for keyword '%s'",
self.persona)
if not transcribed or not threshold:
self._logger.info("Nothing has been said or transcribed.")
continue
self._logger.info("Keyword '%s' has been said!", self.persona)
self._logger.debug("Started to listen actively with threshold: %r",
threshold)
input = self.mic.activeListenToAllOptions(threshold)
self._logger.debug("Stopped to listen actively with threshold: %r",
threshold)
if input:
self.brain.query(input)
else:
self.mic.say("Pardon?")
EDITED CODE:
# -*- coding: utf-8-*-
import logging
from notifier import Notifier
from brain import Brain
class Conversation(object):
def __init__(self, speaker, persona, mic, profile):
self._logger = logging.getLogger(__name__)
self.speaker = speaker #ADDED LINE
self.persona = persona
self.mic = mic
self.profile = profile
self.brain = Brain(mic, profile)
self.notifier = Notifier(profile)
def handleForever(self):
"""
Delegates user input to the handling function when activated.
"""
self._logger.info("Starting to handle conversation with keyword '%s'.",
self.persona)
while True:
# Print notifications until empty
notifications = self.notifier.getAllNotifications()
for notif in notifications:
self._logger.info("Received notification: '%s'", str(notif))
self._logger.debug("Started listening for keyword '%s'",
self.persona)
threshold, transcribed = self.mic.passiveListen(self.persona)
self._logger.debug("Stopped listening for keyword '%s'",
self.persona)
if not transcribed or not threshold:
self._logger.info("Nothing has been said or transcribed.")
continue
self._logger.info("Keyword '%s' has been said!", self.persona)
self._logger.debug("Started to listen actively with threshold: %r",
threshold)
input = self.mic.activeListenToAllOptions(threshold)
self._logger.debug("Stopped to listen actively with threshold: %r",
threshold)
if input:
self.brain.query(input)
else:
self.speaker.play(jasperpath.data('audio', 'SpeechMis.wav')) #ADDED LINE
self.mic.say("Pardon?")
When I run the Jasper software that includes this modified code I get the following error:
Traceback (most recent call last):
File "/home/pi/jasper/jasper.py", line 151, in <module>
app.run()
File "/home/pi/jasper/jasper.py", line 120, in run
conversation = Conversation("JASPER", self.mic, self.config)
TypeError: int() takes exactly 5 arguments (4 given)
I have looked at other TypeError questions and have read the code carefully. I still don't know what I'm doing wrong.
Upvotes: 0
Views: 1111
Reputation: 81594
class Conversation(object):
def __init__(self, speaker, persona, mic, profile):
...
conversation = Conversation("JASPER", self.mic, self.config)
You modified Conversation.__init__
signature and now it expects 4 arguments (speaker
, persona
, mic
, profile
), yet the calling code still provides values for only the first 3.
In order to modify the class while not breaking existing code, add the new argument to the end and use default value:
class Conversation(object):
def __init__(self, persona, mic, profile, speaker=None):
Upvotes: 2