Skip to content

Commit

Permalink
Remove bad logger
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Aug 13, 2017
1 parent b34fb6e commit 3842a7f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
8 changes: 0 additions & 8 deletions pynuance/logger.py

This file was deleted.

23 changes: 12 additions & 11 deletions pynuance/nlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import asyncio
import binascii
import logging

import aiohttp

from pynuance.logger import LOGGER_ROOT
from pynuance.websocket import WebsocketConnection, connection_handshake
from pynuance.libs.languages import NLU_LANGUAGES
from pynuance.libs.error import PyNuanceError
from pynuance.recorder import Recorder, listen_microphone


_LOGGER_NLU = LOGGER_ROOT.getChild("nlu")


def understand_audio(app_id, app_key, context_tag, language):
def understand_audio(app_id, app_key, context_tag, language, logger=None):
"""NLU audio wrapper"""
# transform language
if logger is None:
logger = logging.getLogger("pynuance").getChild("nlu").getChild("audio")
nlu_language = NLU_LANGUAGES.get(language)
if nlu_language is None:
raise PyNuanceError("Language should be in "
Expand All @@ -26,7 +25,7 @@ def understand_audio(app_id, app_key, context_tag, language):
try:
loop = asyncio.get_event_loop()
except RuntimeError:
_LOGGER_NLU.debug("Get New event loop")
logger.debug("Get New event loop")
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

Expand All @@ -40,7 +39,7 @@ def understand_audio(app_id, app_key, context_tag, language):
context_tag,
nlu_language,
recorder=recorder,
logger=_LOGGER_NLU,))
logger=logger,))
# loop.close()
if interpretations is False:
# The user did not speak
Expand Down Expand Up @@ -114,19 +113,21 @@ def _nlu_audio(loop, url, app_id, app_key, context_tag, # pylint: disable=R0914
return interpretation


def understand_text(app_id, app_key, context_tag, language, text):
def understand_text(app_id, app_key, context_tag, language, text, logger=None):
"""Nlu text wrapper"""
if logger is None:
logger = logging.getLogger("pynuance").getChild("nlu").getChild("text")
# transform language
nlu_language = NLU_LANGUAGES.get(language)
if nlu_language is None:
raise PyNuanceError("Language should be in "
"{}".format(", ".join(NLU_LANGUAGES.keys())))

_LOGGER_NLU.debug("Text received: {}".format(text))
logger.debug("Text received: {}".format(text))
try:
loop = asyncio.get_event_loop()
except RuntimeError:
_LOGGER_NLU.debug("Get New event loop")
logger.debug("Get New event loop")
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

Expand All @@ -138,7 +139,7 @@ def understand_text(app_id, app_key, context_tag, language, text):
context_tag,
text,
nlu_language,
_LOGGER_NLU,
logger,
))
# loop.close()
if interpretations is False:
Expand Down
13 changes: 6 additions & 7 deletions pynuance/stt.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""Provides Speech-To-Text functions"""
import asyncio
import binascii
import logging

from pynuance.logger import LOGGER_ROOT
from pynuance.websocket import WebsocketConnection, connection_handshake
from pynuance.recorder import Recorder, listen_microphone


_LOGGER_STT = LOGGER_ROOT.getChild("stt")


@asyncio.coroutine
def do_recognize(loop, url, app_id, app_key, language, # pylint: disable=R0914,R0914
recorder, logger):
"""Main function for Speech-To-Text"""
# Websocket client
client = WebsocketConnection(url, _LOGGER_STT)
client = WebsocketConnection(url, logger)
yield from client.connect(app_id, app_key)

# Init Nuance communication
Expand Down Expand Up @@ -67,11 +64,13 @@ def do_recognize(loop, url, app_id, app_key, language, # pylint: disable=R0914,
return msg_list


def speech_to_text(app_id, app_key, language):
def speech_to_text(app_id, app_key, language, logger=None):
"""Speech to text from mic and return result.
This function auto detect a silence
"""
if logger is None:
logger = logging.getLogger("pynuance").getChild("stt")
try:
loop = asyncio.get_event_loop()
except RuntimeError:
Expand All @@ -87,7 +86,7 @@ def speech_to_text(app_id, app_key, language):
binascii.unhexlify(app_key),
language,
recorder=recorder,
logger=_LOGGER_STT,
logger=logger,
))
loop.stop()
return output
10 changes: 5 additions & 5 deletions pynuance/tts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provides Text-To-Speech functions"""
import asyncio
import binascii
import logging

import pyaudio
try:
Expand All @@ -14,7 +15,6 @@
opus = None

from pynuance.websocket import WebsocketConnection
from pynuance.logger import LOGGER_ROOT
from pynuance.libs.languages import LANGUAGES
from pynuance.libs.error import PyNuanceError

Expand Down Expand Up @@ -47,8 +47,6 @@
"male": "thomas"},
}

_LOGGER_TTS = LOGGER_ROOT.getChild("tts")


def _get_opus_decoder_func(decoder):
"""Create function for Opus codec"""
Expand Down Expand Up @@ -164,8 +162,10 @@ def do_synthesis(url, app_id, app_key, language, voice, codec,
audio_player.terminate()


def text_to_speech(app_id, app_key, language, voice, codec, text):
def text_to_speech(app_id, app_key, language, voice, codec, text, logger=None):
"""Read a text with a given language, voice and code"""
if logger is None:
logger = logging.getLogger("pynuance").getChild("tts")
voices_by_lang = dict([(l['code'], l['voice']) for l in LANGUAGES.values()])
if language not in voices_by_lang:
raise PyNuanceError("Language should be in "
Expand All @@ -177,5 +177,5 @@ def text_to_speech(app_id, app_key, language, voice, codec, text):
_loop = asyncio.get_event_loop()
_loop.run_until_complete(do_synthesis("https://ws.dev.nuance.com/v1/",
app_id, binascii.unhexlify(app_key), language, voice, codec,
text, logger=_LOGGER_TTS))
text, logger=logger))
_loop.stop()

0 comments on commit 3842a7f

Please sign in to comment.