Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a event listener to respond with text without speaking #38

Open
wants to merge 2 commits into
base: 20.08
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def query(self, input):
data = self.request({"query": {"input": input}})
return wolframalpha.Result(BytesIO(data.content))

def query_to_string(self, input):
data = self.request({"query": {"input": input}})
return data.content.decode("utf-8")

def spoken(self, query, lat_lon, units='metric'):
try:
Expand Down Expand Up @@ -147,6 +150,7 @@ def __init_client(self):
def initialize(self):
self._setup()
self.settings_change_callback =self.on_settings_changed
self.add_event('skill.wolfram.unspoken.request', self.emit_text_result)

def on_settings_changed(self):
self.log.debug("settings changed")
Expand Down Expand Up @@ -176,6 +180,10 @@ def get_result(self, res):
except:
return result

def emit_text_result(self, message):
response = self.client.query_to_string(message.data.get('query'))
self.bus.emit(Message("skill.wolfram.unspoken.response", {'result': response}))

def CQS_match_query_phrase(self, utt):
self.log.debug("WolframAlpha query: " + utt)

Expand Down