# -*- coding: utf-8 -*-
from __future__ import division
from ..__load__ import *

class Base(object):

	def __init__(self, sdk = False):
		self.name = self.__class__.__name__
		self.name = self.name.lower()
		if sdk == True:
			self.sdk = Demeter.service(self.name, 'sdk')
		pass

	# Automatic Speech Recognition asr 自动语音识别
	@abstractmethod
	def asr(self, fp):
		pass

	# AI 聊天机器人
	@abstractmethod
	def chat(self, texts):
		pass

	# Text To Speech 人机对话 文本转语音
	@abstractmethod
	def tts(self, phrase):
		pass

	# Natural Language Understanding 自然语言理解
	@abstractmethod
	def nlu(self, query):
		pass

	# 设置工具
	@abstractmethod
	def setting(self, **args):
		pass

	def asrLog(self, state, msg = ''):
		if state == 1:
			method = 'info'
			text = '语音识别成功'
		else:
			method = 'critical'
			text = '语音识别失败'
		return self.log(method, text, msg)

	def chatLog(self, state, msg = ''):
		if state == 1:
			method = 'info'
			text = '回答'
		else:
			method = 'critical'
			text = '未做回答'
		return self.log(method, text, msg)

	def ttsLog(self, state, msg = ''):
		if state == 1:
			method = 'info'
			text = '语音合成成功，合成路径'
		else:
			method = 'critical'
			text = '语音合成失败'
		return self.log(method, text, msg)

	def log(self, method, text, msg = ''):
		logger = getattr(Demeter.logger, method)
		logger('{}-{}：{}'.format(self.name, text, msg))
		return msg;