示例#1
0
    def __init__(self, voice):
        super(WindowWidget, self).__init__()
        self.sess = None
        self.captioner = None
        self.prepare_questioner()
        self.prepare_captioner()
        self.threadpool = QtCore.QThreadPool()
        self.questioner_running = False
        self.applying_output = False

        global graph
        graph = tf.get_default_graph()

        if voice:
            self.tts = TTS()
        else:
            self.tts = None

        # Viewing region
        self.viewing_region = QtWidgets.QLabel(self)
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.viewing_region)

        # Load button
        self.load_button = QtWidgets.QPushButton('Load image')
        self.load_button.clicked.connect(self.load_button_clicked)
        right_sidebar = QtWidgets.QVBoxLayout()
        right_sidebar.addWidget(self.load_button)

        # Extra instructions region
        self.instr_region = QtWidgets.QLabel(self)
        self.instr_region.setText('Or drop an image onto this window.')
        right_sidebar.addWidget(self.instr_region)
        right_sidebar.addStretch()

        # Progress bar
        self.progress = QtWidgets.QProgressBar(self)
        self.progress.setMaximum(100)
        right_sidebar.addWidget(self.progress)
        self.progress.hide()

        # Text region
        self.text_region = QtWidgets.QLabel(self)
        self.text_region.setFrameStyle(QtWidgets.QFrame.Panel
                                       | QtWidgets.QFrame.Sunken)
        self.text_region.setWordWrap(True)
        self.text_region.setMargin(8)
        self.text_region.setText('...')
        right_sidebar.addWidget(self.text_region)
        layout.addLayout(right_sidebar)

        # Launch
        self.setWindowIcon(QtGui.QIcon(os.path.join('icon', 'question.png')))
        self.setLayout(layout)
        self.setAcceptDrops(True)
        self.show()
示例#2
0
 def add_duet(self, text, part, percentage=1.0):
     tts = TTS(Voice(Voice.Language.enUS, Voice.Sex.male, "Joey"))
     aud, dr = sf.read(tts.speak(text))
     aud = aud.repeat(2, axis=0)
     dr = dr * 2
     one_part_length = len(self.final_audio) / self.times
     if one_part_length < len(aud):
         print('Warning: Duet is longer than the beat!')
     start = int(one_part_length * part)
     length = len(aud)
     self.final_audio[start:start + length:] += aud * percentage
     return self.final_audio, self.sr
示例#3
0
 def __init__(self,
              detector_cfg_path,
              detector_weights_path,
              bert_cfg_path,
              bert_weights_path,
              object_vocab_path,
              tacotron_weights_path,
              waveglow_cfg_path,
              waveglow_weights_path,
              cpu_device,
              gpu_device,
              fc_layer=0,
              max_caption_length=67,
              sampling_rate=22050):
     """
     args:
         detector_cfg_path: path to the detector config
         detector_weights_path: path to the detector weights
         bert_cfg_path: path to the bert decoder config
         bert_weights_path: path to the bert decoder weights
         tacotron_weights_path: path to the tacotron weights
         waveglow_weights_path: path to the waveglow weights
         cpu_device: The cpu device to run some parts of visualization
         gpu_device: The gpu device to run the bulk of computations, currently requires at least 1 GPU device
         fc_layer: the fully connected layer from the detector to extract features from, 0-indexed
         max_caption_length: the maximum number of tokens the caption can be
         sampling_rate: the rate that audio representations are sampled per second
     """
     self.captioner = Captioner(detector_cfg_path, detector_weights_path,
                                bert_cfg_path, bert_weights_path,
                                object_vocab_path, cpu_device, gpu_device,
                                fc_layer, max_caption_length)
     device = gpu_device if gpu_device else cpu_device
     self.tts = TTS(tacotron_weights_path, waveglow_cfg_path,
                    waveglow_weights_path, device, sampling_rate)
示例#4
0
    def main(self):

        for imageName, params in self._inputConfig.items():
            try:
                print(self.flag.taskStarted.format(imageName))
                imagePath = self.getAbsPath('/in', imageName)

                if not os.path.isfile(imagePath):
                    if os.path.isfile(self.getAbsPath('/', imageName)):
                        raise customExceptions.FileTypeNotSupportedError(
                            imagePath)
                    raise customExceptions.FileNotFoundError(imagePath)

                text = OCR().imageToString(path=imagePath,
                                           lang=params['language'])

                textFilePath = self.getAbsPath('/text', imageName,
                                               self._TEXT_EXTENSION)
                self.save(path=textFilePath, text=text)

                soundFilePath = self.getAbsPath('/sound', imageName,
                                                self._SOUND_EXTENSION)
                TTS().textToSpeech(path=textFilePath,
                                   voice=params['voice'],
                                   latency=params['latency'],
                                   out=soundFilePath)
                print(self.flag.taskEnded)
            except customExceptions.CustomError:
                pass
            except Exception as e:
                print(e)

        self.renameInputFiles()
        print(self.flag.executionEnded)
示例#5
0
    def main(self):

        for filename, params in self._inputConfig.items():
            try:
                print(self.flag.taskStarted.format(filename))
                path = self.getAbsPath('/in', filename)

                if not os.path.isfile(path):
                    if os.path.isfile(self.getAbsPath('/', filename)):
                        raise customExceptions.FileTypeNotSupportedError(
                            filename)
                    raise customExceptions.FileNotFoundError(filename)

                TTS().textToSpeech(path=path,
                                   voice=params['voice'],
                                   latency=params['latency'],
                                   out=self.getAbsPath('/out', filename,
                                                       self._EXTENSION))
                print(self.flag.taskEnded)
            except customExceptions.CustomError:
                pass
            except Exception as e:
                print(e)

        self.renameInputFiles()
        print(self.flag.executionEnded)
    def __init__(self, commander: Commander):
        self.r = sr.Recognizer()
        self.commander: Commander = commander
        self.tts_engine: TTS = TTS()

        self.listen_command_queue: Queue = Queue()
        self.listening_for_command: bool = False
示例#7
0
    def get_audio_voicerss(self, **kwargs):
        words = kwargs.get('words', None)
        cache = kwargs.get('cache', None)
        file_path = kwargs.get('file_path', None)
        language = kwargs.get('language', None)
        payload = Voicerss.get_payload(language, words)

        return TTS.get_audio(file_path, cache, payload, self.TTS_URL)
示例#8
0
    def get_audio_voxygen(self, **kwargs):
        words = kwargs.get('words', None)
        cache = kwargs.get('cache', None)
        file_path = kwargs.get('file_path', None)
        voice = kwargs.get('voice', None)
        payload = Voxygen.get_payload(voice, words)

        return TTS.get_audio(file_path, cache, payload, self.TTS_URL)
示例#9
0
    def __init__(self, use_speech):
        self.tts = TTS()

        self.use_speech = use_speech

        if self.use_speech:
            self.stt = STT()

        self.chatbot = ChatBot(
            'JARVIS',
            storage_adapter='chatterbot.storage.JsonFileStorageAdapter',
            filters=['chatterbot.filters.RepetitiveResponseFilter'],
            logic_adapters=[{
                'import_path': 'chatterbot.logic.BestMatch'
            }])

        self.chatbot.set_trainer(ChatterBotCorpusTrainer)
        self.chatbot.train("chatterbot.corpus.english.greetings")
示例#10
0
    def get_audio_acapela(self, **kwargs):
        language = kwargs.get('language', None)
        words = kwargs.get('words', None)
        cache = kwargs.get('cache', None)
        file_path = kwargs.get('file_path', None)
        voice = kwargs.get('voice', None)
        payload = Acapela.get_payload(language, voice, words)
        url = Acapela.get_audio_link(self.TTS_URL, payload)

        return TTS.get_audio(file_path, cache, payload, url)
示例#11
0
class Assistant(object):
    def __init__(self, use_speech):
        self.tts = TTS()

        self.use_speech = use_speech

        if self.use_speech:
            self.stt = STT()

        self.chatbot = ChatBot(
            'JARVIS',
            storage_adapter='chatterbot.storage.JsonFileStorageAdapter',
            filters=['chatterbot.filters.RepetitiveResponseFilter'],
            logic_adapters=[{
                'import_path': 'chatterbot.logic.BestMatch'
            }])

        self.chatbot.set_trainer(ChatterBotCorpusTrainer)
        self.chatbot.train("chatterbot.corpus.english.greetings")

    def search_wolfram(self, input):
        try:
            search_result = wolfram_client.query(input)
            self.say(next(search_result.results).text)
            return True
        except:
            return False

    def say(self, message):
        self.tts.say(message)

    def respond(self, message):
        self.say(self.chatbot.get_response(message))

    def get_input(self):
        if (self.use_speech):
            input = self.stt.listen()
            print 'User: {}'.format(input)
        else:
            input = raw_input('User: ')

        return input
示例#12
0
文件: text.py 项目: sudhinsr/jarvis
class Text(object):
    def __init__(self):

        self.stt_engine = STT()
        self.tts_engine = TTS()
        self.mic = Mic(self.tts_engine, self.stt_engine, self.stt_engine)
        self.selection = Selection(self.tts_engine)

    def handle(self):

        while True:
            threshold, translate = self.mic.passiveListen("JARVIS")
            if not translate or not threshold:
                continue
            input = self.mic.activeListen(threshold)
            print input
            if input:
                string = self.selection.select(input)
            else:
                self.tts_engine.say("Pardon?")
示例#13
0
    def say_tts(self, text, generate_only=False):
        full_path = TTS.create(text)

        if generate_only:
            return

        FNULL = open(os.devnull, "w")

        self.stop_sound()
        if not self.jack:
            self.playProcess = subprocess.Popen(["aplay", full_path],
                                                stdout=FNULL,
                                                stderr=subprocess.STDOUT)
        else:
            # self.playProcess = subprocess.Popen(["aplay", "-D", "hw:0,0", full_path], stdout=FNULL, stderr=subprocess.STDOUT)
            self.playProcess = subprocess.Popen(
                ["aplay", "-D", "hw:0,0", full_path],
                stdout=FNULL,
                stderr=subprocess.STDOUT)
示例#14
0
def main():

    print("Imports data into InfluxDB. Use --help for parameters")

    use_importers = read_parameters()

    importers = [Catalanitzador(), Programs(), AdSense(), Analytics(),
                 TTS(), TM(), DictMutilingual(), Criteo(), Traductor(), STT(), NeuralTranslator()]

    for importer in importers:
        try:
            if use_importers and type(importer).__name__.lower() not in use_importers:
                continue

            importer.do()

        except Exception as e:
            msg = "Error at importer '{0}': {1}"
            print(msg.format(type(importer).__name__, e))
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
示例#15
0
from flask import Flask, request, render_template, redirect, url_for, Response
from flaskext.mysql import MySQL
from tts import TTS
from selection import Selection
from camera import VideoCamera

tts = TTS()
s = Selection(tts)
mysql = MySQL()
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = '******'
app.config['MYSQL_DATABASE_PASSWORD'] = '******'
app.config['MYSQL_DATABASE_DB'] = 'jarvis'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)

data = None


@app.route("/", methods=['GET', 'POST'])
def auth():
    con = mysql.connect()
    cursor = con.cursor()
    if request.method == 'POST':
        email = request.form["email"]
        passw = request.form["passw"]

        cursor.execute("select * from users where email='" + email +
                       "' and password='******'")
        data = cursor.fetchone()
示例#16
0
文件: main.py 项目: aksh98md/Jason
from PythonUp import read_sheet

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

allIntents = [
    "只是打招呼", "打電話", "文字辨識", "景象辨識", "發簡訊", "罵人", "認人", "拍照", "查詢餘額", "掰掰",
    "None"
]

# run ls /dev/tty* before and after plugging in arduino to find out
ser = serial.Serial('/dev/ttyACM0', 9600)

# initilialize an Microsoft_ASR object

tts = TTS()
fft = FFT(time_gap=0.5)
ms_asr = Microsoft_ASR()

temperature_flag = False

while True:
    #st = time.time()
    print("\rPress to activate your voice assistant...", end='  ')
    input_state = GPIO.input(18)
    ret = None
    if input_state == True:
        # Button Pressed
        print()
        intent, entities = callLUIS(ms_asr.listen_for_speech())
示例#17
0
文件: chef.py 项目: lorden/chef
from tts import TTS
from recipe_parser import RecipeParser


if __name__ == '__main__':
    tts = TTS()
    rp = RecipeParser('icecreamcone.json')
    text = raw_input('Say:')
    while text:
        if text == 'ingredients':
            ingredients = rp.get_ingredients()
            for ingredient in ingredients:
                tts.say(ingredient)
        elif text == 'instructions':
            instructions = rp.get_instruction()
            for instruction in instructions:
                tts.say(instruction[0:100])
        elif rp.find_ingredient(text):
            ingredient = rp.find_ingredient(text)[0]
            tts.say(ingredient['amount'] + ' ' + ingredient['ingredient'])

        text = raw_input('Say:')
示例#18
0
class PiSmart(_Basic_class):
    _class_name = 'Amateur PiSmart'

    ON = 1
    OFF = 0

    def __init__(self, *item):
        self._ps            = pismart.PiSmart()
        self._ps.DEBUG = 'error'
        self.servo_switch   = self._ps.servo_switch
        self.pwm_switch     = self._ps.pwm_switch
        self.motor_switch   = self._ps.motor_switch
        self.speaker_switch = self._ps.speaker_switch
        if len(item) == 0:
            self.ALL_init()
        elif item == "manual":
            pass

    def ALL_init(self):
        self.ADC_init()
        self.Servo_init()
        self.LED_init()
        self.Motor_init()
        self.TTS_init()
        self.STT_init()

    def ADC_init(self):
        from adc import ADC
        self._A0 = ADC(0)
        self._A1 = ADC(1)
        self._A2 = ADC(2)
        self._A3 = ADC(3)
        self._A4 = ADC(4)
        self._A0.DEBUG = 'error'
        self._A1.DEBUG = 'error'
        self._A2.DEBUG = 'error'
        self._A3.DEBUG = 'error'
        self._A4.DEBUG = 'error'

    def Servo_init(self):
        from servo import Servo
        self._servo0 = Servo(0)
        self._servo1 = Servo(1)
        self._servo2 = Servo(2)
        self._servo3 = Servo(3)
        self._servo4 = Servo(4)
        self._servo5 = Servo(5)
        self._servo6 = Servo(6)
        self._servo7 = Servo(7)
        self.servo_switch(self.ON)
        self._servo0.DEBUG = 'error'
        self._servo1.DEBUG = 'error'
        self._servo2.DEBUG = 'error'
        self._servo3.DEBUG = 'error'
        self._servo4.DEBUG = 'error'
        self._servo5.DEBUG = 'error'
        self._servo6.DEBUG = 'error'
        self._servo7.DEBUG = 'error'

    def PWM_init(self):
        from pwm import PWM
        self._pwm0 = PWM(0)
        self._pwm1 = PWM(1)
        self._pwm2 = PWM(2)
        self._pwm3 = PWM(3)
        self._pwm4 = PWM(4)
        self._pwm5 = PWM(5)
        self._pwm6 = PWM(6)
        self._pwm7 = PWM(7)
        self.pwm_switch(self.ON)
        self._pwm0.DEBUG = 'error'
        self._pwm1.DEBUG = 'error'
        self._pwm2.DEBUG = 'error'
        self._pwm3.DEBUG = 'error'
        self._pwm4.DEBUG = 'error'
        self._pwm5.DEBUG = 'error'
        self._pwm6.DEBUG = 'error'
        self._pwm7.DEBUG = 'error'

    def LED_init(self):
        from led import LED
        self._led = LED()
        self._led.DEBUG = 'error'

    def Motor_init(self):
        from motor import Motor
        self._motor_a = Motor(Motor.MotorA)
        self._motor_b = Motor(Motor.MotorB)
        self._motor_a.DEBUG = 'error'
        self._motor_b.DEBUG = 'error'
        self.motor_switch(self.ON)

    def TTS_init(self):
        from tts import TTS
        self._tts = TTS()
        self._tts.DEBUG = 'error'
        self.speaker_switch(self.ON)
        self.speaker_volume = 100

    def STT_init(self):
        from stt import STT
        self._stt = STT('dictionary', name_calling=False, timeout=10.0, dictionary_update=True)
        self._stt.DEBUG = 'error'
        self.capture_volume = 100

    def ADC_end(self):
        pass
    
    def Servo_end(self):
        self.servo_switch(self.OFF)

    def PWM_end(self):
        self.pwm_switch(self.OFF)

    def Motor_end(self):
        self._motor_a.stop()
        self._motor_b.stop()
        self.motor_switch(self.OFF)

    def LED_end(self):
        self.LED = 0

    def TTS_end(self):
        self._tts.end()
        self.speaker_switch(self.OFF)

    def STT_end(self):
        self._stt.end()


    def end(self):
        self.ADC_end()
        self.LED_end()
        self.Motor_end()
        self.Servo_end()
        self.PWM_end()
        self.STT_end()

    @property
    def power_type(self):
        return self._ps.power_type
    @power_type.setter
    def power_type(self, value):
        self._ps.power_type = value
    @property
    def power_voltage(self):
        return self._ps.power_voltage
    @power_voltage.setter
    def power_voltage(self, value):
        self._ps.power_voltage = value
    @property
    def speaker_volume(self):
        return self._ps.speaker_volume
    @speaker_volume.setter
    def speaker_volume(self, value):
        self._ps.speaker_volume = value
    @property
    def capture_volume(self):
        return self._ps.capture_volume
    @capture_volume.setter
    def capture_volume(self, value):
        self._ps.capture_volume = value
    @property
    def cpu_temperature(self):
        return self._ps.cpu_temperature

    @property
    def A0(self):
        return self._A0.read()
    @property
    def A1(self):
        return self._A1.read()
    @property
    def A2(self):
        return self._A2.read()
    @property
    def A3(self):
        return self._A3.read()
    @property
    def A4(self):
        return self._A4.read()

    @property
    def Servo0(self):
        return self._servo0.angle
    @Servo0.setter
    def Servo0(self, angle):
        self._servo0.angle = angle
    @property
    def Servo1(self):
        return self._servo1.angle
    @Servo1.setter
    def Servo1(self, angle):
        self._servo1.angle = angle
    @property
    def Servo2(self):
        return self._servo2.angle
    @Servo2.setter
    def Servo2(self, angle):
        self._servo2.angle = angle
    @property
    def Servo3(self):
        return self._servo3.angle
    @Servo3.setter
    def Servo3(self, angle):
        self._servo3.angle = angle
    @property
    def Servo4(self):
        return self._servo4.angle
    @Servo4.setter
    def Servo4(self, angle):
        self._servo4.angle = angle
    @property
    def Servo5(self):
        return self._servo5.angle
    @Servo5.setter
    def Servo5(self, angle):
        self._servo5.angle = angle
    @property
    def Servo6(self):
        return self._servo6.angle
    @Servo6.setter
    def Servo6(self, angle):
        self._servo6.angle = angle
    @property
    def Servo7(self):
        return self._servo7.angle
    @Servo7.setter
    def Servo7(self, angle):
        self._servo7.angle = angle

    @property
    def PWM0(self):
        return self._pwm0.value
    @PWM0.setter
    def PWM0(self, value):
        self._pwm0.value = value
    @property
    def PWM1(self):
        return self._pwm1.value
    @PWM1.setter
    def PWM1(self, value):
        self._pwm1.value = value
    @property
    def PWM2(self):
        return self._pwm2.value
    @PWM2.setter
    def PWM2(self, value):
        self._pwm2.value = value
    @property
    def PWM3(self):
        return self._pwm3.value
    @PWM3.setter
    def PWM3(self, value):
        self._pwm3.value = value
    @property
    def PWM4(self):
        return self._pwm4.value
    @PWM4.setter
    def PWM4(self, value):
        self._pwm4.value = value
    @property
    def PWM5(self):
        return self._pwm5.value
    @PWM5.setter
    def PWM5(self, value):
        self._pwm5.value = value
    @property
    def PWM6(self):
        return self._pwm6.value
    @PWM6.setter
    def PWM6(self, value):
        self._pwm6.value = value
    @property
    def PWM7(self):
        return self._pwm7.value
    @PWM7.setter
    def PWM7(self, value):
        self._pwm7.value = value

    @property
    def LED(self):
        return self._led.brightness
    @LED.setter
    def LED(self, value):
        self._led.brightness = value    

    @property
    def MotorA(self):
        return self._motor_a.speed
    @MotorA.setter
    def MotorA(self, value):
        self._motor_a.speed = value
    @property
    def MotorB(self):
        return self._motor_b.speed
    @MotorB.setter
    def MotorB(self, value):
        self._motor_b.speed = value

    @property
    def MotorA_reversed(self):
        return self._motor_a.is_reversed
    @MotorA_reversed.setter
    def MotorA_reversed(self, value):
        self._motor_a.is_reversed = value
    @property
    def MotorB_reversed(self):
        return self._motor_b.is_reversed
    @MotorB_reversed.setter
    def MotorB_reversed(self, value):
        self._motor_b.is_reversed = value

    @property
    def Say(self):
        return self._tts.say
    @Say.setter
    def Say(self, words):
        self._tts.say = words

    @property
    def listen(self):
        return self._stt.recognize()

    @property
    def heard(self):
        return self._stt.heard

    @property
    def result(self):
        return self._stt.result
示例#19
0
# class handles keyboard input and reading of the text
from tts import TTS

# custom gui script for generating tkinter
# windows containing play and quit buttons

from gui import App

import sys
# added to fix a anonying error with pyinstaller
#EX: "[123972] Failed to execute script pyi_rth_win32comgenpy"

app = App()
tts = TTS()

print("Ultimate tts reader:")
print("press escape to quit program <ESC>")

# external loop not part of tkinker thread
# loop exits when the tkinter windows is closed
while app.is_alive():
    # time.sleep(1)
    # print(app.is_alive())
    tts.iterate()
sys.exit()
tts.endloop()
示例#20
0
 def __init__(self):
     TTS.__init__(self)
示例#21
0
 def text_to_speech(self):
     self.tts = TTS()
     text = self.msgText.toPlainText()
     self.tts.read_text(text)
示例#22
0
文件: text.py 项目: sudhinsr/jarvis
    def __init__(self):

        self.stt_engine = STT()
        self.tts_engine = TTS()
        self.mic = Mic(self.tts_engine, self.stt_engine, self.stt_engine)
        self.selection = Selection(self.tts_engine)
示例#23
0
choice = input(
    'Would you like to suggest a topic or should i pick from samples? ')
if choice in 'sample':
    choice = input('Choose from samples: \n 1-) Eminem \n 2-) 50 Cent')
    if choice == '1':
        lyrics = eminem
    elif choice == '2':
        lyrics = fifty_cent
else:
    limit = input("Set a line limit: ")
    lyrics = crawl_lyrics(choice)[:int(limit)]

ap = AudioProcessing()

for text in lyrics:
    text = prepare_text(text)
    tts = TTS(Voice(Voice.Language.enUS, Voice.Sex.male, "Justin"))
    ap.modify(tts.speak(text),
              0.1,
              -1,
              1,
              mid_part=0.05,
              mid_pitch=2,
              mid_stretch=1,
              accel=1.0)
aud, br = ap.insert_beat()
aud, br = ap.add_duet('Drop the beat DJ!', 0, 2)
aud, br = ap.add_duet('Aha. Yeah. Aha!', 3, 0.5)
ap.write(aud, br, name=choice)
示例#24
0
from tts import TTS
from recipe_parser import RecipeParser

if __name__ == '__main__':
    tts = TTS()
    rp = RecipeParser('icecreamcone.json')
    text = raw_input('Say:')
    while text:
        if text == 'ingredients':
            ingredients = rp.get_ingredients()
            for ingredient in ingredients:
                tts.say(ingredient)
        elif text == 'instructions':
            instructions = rp.get_instruction()
            for instruction in instructions:
                tts.say(instruction[0:100])
        elif rp.find_ingredient(text):
            ingredient = rp.find_ingredient(text)[0]
            tts.say(ingredient['amount'] + ' ' + ingredient['ingredient'])

        text = raw_input('Say:')
示例#25
0
#!/usr/bin/python3

import sys
sys.path += ['../']

import ScoreDraft
from tts import TTS

buf = ScoreDraft.TrackBuffer(1)
TTS("光头", buf)
ScoreDraft.WriteTrackBufferToWav(buf, 'test.wav')
	out = asr_model.transcribe(wav)
	toc = time.time()
	app.logger.info("ASR Model Transcription: "+out)
	app.logger.info("ASR Duration: {} seconds".format(toc-tic))
	# form response
	flask_response= app.response_class(response=flask.json.dumps({"text": out}),
										status=200,
										mimetype='application/json' )
	return flask_response





if __name__ == '__main__':
	conf = parse_yaml("conf.yaml")
	
	# load ASR model
	app.logger.info("===== Loading ASR Model =====")
	asr_conf = conf["asr"]
	asr_model = ASR(asr_conf)
	
	# load TTS model
	app.logger.info("===== Loading TTS Model =====")
	tts_conf = conf["tts"]
	tts_model = TTS(tts_conf)

	# run server
	app.logger.info("===== Running the Server =====")
	app.run(host="0.0.0.0", port=5000)
示例#27
0
from dictionary import Word
from language import *
from tts import TTS

lang = Language("lang1")

tts = TTS()

for word in lang.dictionary:
    try:
        letters = lang.romanization.phonemes_to_roman(word.phonemes)
        raw_letters = lang.romanization.phonemes_to_roman(word.raw_phonemes)
        print("{}\t{}\t{}".format(raw_letters, letters,
                                  ", ".join(word.definitions)))
    except:
        print("FAIL: {} {}".format(word.phonemes, word.definitions))

#lang.dictionary.add_morpheme("_", "ahtokira", ["..."])
#word = lang.dictionary.add_word("_", ["..."])
#ipa = str(word)
#tts.say_ipa(ipa)

tts = TTS()
while True:
    try:
        command = input(": ")

        words = command.split(" ")

        all_ipa = []
示例#28
0
 def __init__(self):
     TTS.__init__(self, AudioPlayer.PLAYER_WAV)
示例#29
0
from tts import TTS
from asr import ASR

TTS.speak(ASR.listen())
示例#30
0
 def TTS_init(self):
     from tts import TTS
     self._tts = TTS()
     self._tts.DEBUG = 'error'
     self.speaker_switch(self.ON)
     self.speaker_volume = 100
示例#31
0
def run_bot(config: granula.Config):
    locks: DefaultDict[Any, Lock] = collections.defaultdict(threading.Lock)
    bot = telebot.TeleBot(token=config.telegram.key)
    state_machine: StateMachine = get_state_machine(config)
    tts = TTS(config=config['voice_kit'])
    game_storage = GameStorage(config=config['storage'])

    def _send(message: telebot.types.Message, response: str):
        return bot.send_message(chat_id=message.chat.id,
                                text=response,
                                parse_mode='html')

    def _send_voice(message: telebot.types.Message, voice):
        return bot.send_voice(chat_id=message.chat.id, voice=voice)

    @bot.message_handler(commands=['start'])
    def _start(message: telebot.types.Message):
        with locks[message.chat.id]:
            _send(message, response='Привествую тебя. Нажми /start_quest :)')

    def _send_response(message: telebot.types.Message):
        chat_id = message.chat.id
        user_id = str(
            message.from_user.id) if message.from_user else '<unknown>'

        with locks[chat_id]:
            try:
                context = Context(message.text, user_id)
                response = state_machine.get_response(context)
                response_text = response.text if response is not None else 'Ответа нет'
            except KeyboardInterrupt:
                return
            except Exception as e:
                logger.exception(e)
                response_text = 'Произошла ошибка'

            # _send(message, response=response_text)

            bot.send_poll(chat_id,
                          question='ты кто',
                          options=["Олег", 'не Олег'],
                          is_anonymous=False,
                          type='quiz',
                          correct_option_id=1,
                          open_period=10)

            # print(bot.poll_answer_handlers)

            # data = tts.text2audio(response_text)
            # message = _send_voice(message, voice=data)
            # print(message.voice.file_id)

    @bot.poll_answer_handler()
    def handle_poll_answer(poll_answer: telebot.types.PollAnswer):
        print(poll_answer)
        if poll_answer.options_ids[0] == 1:
            print('верно')
        else:
            print('неверно')

    @bot.message_handler()
    def send_response(message: telebot.types.Message):  # pylint:disable=unused-variable
        try:
            _send_response(message)
        except KeyboardInterrupt:
            return
        except Exception as e:
            logger.exception(e)

    logger.info('Telegram bot started')
    bot.polling(none_stop=True)
示例#32
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(802, 592)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        spacerItem = QtWidgets.QSpacerItem(28, 530,
                                           QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem, 0, 0, 8, 1)
        spacerItem1 = QtWidgets.QSpacerItem(705, 13,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Fixed)
        self.gridLayout.addItem(spacerItem1, 0, 1, 1, 2)
        spacerItem2 = QtWidgets.QSpacerItem(28, 530,
                                            QtWidgets.QSizePolicy.Fixed,
                                            QtWidgets.QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem2, 0, 3, 8, 1)
        self.msgs_tableWidget = QtWidgets.QTableWidget(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.msgs_tableWidget.sizePolicy().hasHeightForWidth())
        self.msgs_tableWidget.setSizePolicy(sizePolicy)
        self.msgs_tableWidget.setObjectName("msgs_tableWidget")
        self.msgs_tableWidget.setColumnCount(4)
        self.msgs_tableWidget.setRowCount(0)
        self.msgs_tableWidget.setHorizontalHeaderLabels(
            ['Date', 'From', 'Subject', 'Message'])
        self.msgs_tableWidget.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        self.msgs_tableWidget.verticalHeader().setVisible(False)
        self.gridLayout.addWidget(self.msgs_tableWidget, 1, 1, 1, 2)
        self.refresh_btn = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.refresh_btn.sizePolicy().hasHeightForWidth())
        self.refresh_btn.setSizePolicy(sizePolicy)
        self.refresh_btn.setObjectName("refresh_btn")
        self.gridLayout.addWidget(self.refresh_btn, 2, 1, 1, 2)
        spacerItem3 = QtWidgets.QSpacerItem(705, 17,
                                            QtWidgets.QSizePolicy.Minimum,
                                            QtWidgets.QSizePolicy.Fixed)
        self.gridLayout.addItem(spacerItem3, 3, 1, 1, 2)
        self.labelfrom = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.labelfrom.sizePolicy().hasHeightForWidth())
        self.labelfrom.setSizePolicy(sizePolicy)
        self.labelfrom.setObjectName("labelfrom")
        self.gridLayout.addWidget(self.labelfrom, 4, 1, 1, 1)
        self.from_label = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.from_label.sizePolicy().hasHeightForWidth())
        self.from_label.setSizePolicy(sizePolicy)
        self.from_label.setText("")
        self.from_label.setObjectName("from_label")
        self.gridLayout.addWidget(self.from_label, 4, 2, 1, 1)
        self.labelsubject = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.labelsubject.sizePolicy().hasHeightForWidth())
        self.labelsubject.setSizePolicy(sizePolicy)
        self.labelsubject.setObjectName("labelsubject")
        self.gridLayout.addWidget(self.labelsubject, 5, 1, 1, 1)
        self.subject_label = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.subject_label.sizePolicy().hasHeightForWidth())
        self.subject_label.setSizePolicy(sizePolicy)
        self.subject_label.setText("")
        self.subject_label.setObjectName("subject_label")
        self.gridLayout.addWidget(self.subject_label, 5, 2, 1, 1)
        self.msgText = QtWidgets.QPlainTextEdit(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.msgText.sizePolicy().hasHeightForWidth())
        self.msgText.setSizePolicy(sizePolicy)
        self.msgText.setObjectName("msgText")
        self.gridLayout.addWidget(self.msgText, 6, 1, 1, 2)
        self.readMsg_btn = QtWidgets.QPushButton(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.readMsg_btn.sizePolicy().hasHeightForWidth())
        self.readMsg_btn.setSizePolicy(sizePolicy)
        self.readMsg_btn.setObjectName("readMsg_btn")
        self.gridLayout.addWidget(self.readMsg_btn, 7, 1, 1, 2)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 802, 21))
        self.menubar.setObjectName("menubar")
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        self.menuHelp = QtWidgets.QMenu(self.menubar)
        self.menuHelp.setObjectName("menuHelp")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.actionAbout = QtWidgets.QAction(MainWindow)
        self.actionAbout.setObjectName("actionAbout")
        self.menuFile.addAction(self.actionExit)
        self.menuHelp.addAction(self.actionAbout)
        self.menubar.addAction(self.menuFile.menuAction())
        self.menubar.addAction(self.menuHelp.menuAction())

        self.msgs_tableWidget.cellClicked.connect(
            self.cell_was_clicked)  # ==== TRIGGER
        self.refresh_btn.clicked.connect(self.readEmail)
        self.readMsg_btn.clicked.connect(self.text_to_speech)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

        self.readEmail()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.labelfrom.setText(_translate("MainWindow", "From    :"))
        self.labelsubject.setText(_translate("MainWindow", "Subject :"))
        self.readMsg_btn.setText(_translate("MainWindow", "Read message"))
        self.refresh_btn.setText(_translate("MainWindow", "Refresh"))
        self.menuFile.setTitle(_translate("MainWindow", "File"))
        self.menuHelp.setTitle(_translate("MainWindow", "Help"))
        self.actionExit.setText(_translate("MainWindow", "Exit"))
        self.actionAbout.setText(_translate("MainWindow", "About"))

    def readEmail(self):
        self.read_email = ReadEmail()
        vals = self.read_email.read_email()

        print(vals)
        row_numbers = []
        column_numbers = []

        self.msgs_tableWidget.setRowCount(len(vals))

        for row_number, row_data in enumerate(vals):
            for column_number, data in enumerate(row_data):
                row_numbers.append(row_number)
                column_numbers.append(column_number)

        values = []

        for val in vals:
            for i in val:
                values.append(i)

        print(values)

        for i in range(len(values)):
            self.msgs_tableWidget.setItem(
                row_numbers[i], column_numbers[i],
                QtWidgets.QTableWidgetItem(str(values[i])))

    def cell_was_clicked(self, row, column):  # Fungsi trigger jika row diklik
        sent_from_item = self.msgs_tableWidget.item(row, 1)
        subject_item = self.msgs_tableWidget.item(row, 2)
        message_item = self.msgs_tableWidget.item(row, 3)

        self.sent_from = sent_from_item.text()
        self.subject = subject_item.text()
        self.message = message_item.text()

        self.from_label.setText(self.sent_from)
        self.subject_label.setText(self.subject)
        self.msgText.setPlainText(self.message)

    def text_to_speech(self):
        self.tts = TTS()
        text = self.msgText.toPlainText()
        self.tts.read_text(text)
示例#33
0
class WindowWidget(QtWidgets.QWidget):
    def __init__(self, voice):
        super(WindowWidget, self).__init__()
        self.sess = None
        self.captioner = None
        self.prepare_questioner()
        self.prepare_captioner()
        self.threadpool = QtCore.QThreadPool()
        self.questioner_running = False
        self.applying_output = False

        global graph
        graph = tf.get_default_graph()

        if voice:
            self.tts = TTS()
        else:
            self.tts = None

        # Viewing region
        self.viewing_region = QtWidgets.QLabel(self)
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.viewing_region)

        # Load button
        self.load_button = QtWidgets.QPushButton('Load image')
        self.load_button.clicked.connect(self.load_button_clicked)
        right_sidebar = QtWidgets.QVBoxLayout()
        right_sidebar.addWidget(self.load_button)

        # Extra instructions region
        self.instr_region = QtWidgets.QLabel(self)
        self.instr_region.setText('Or drop an image onto this window.')
        right_sidebar.addWidget(self.instr_region)
        right_sidebar.addStretch()

        # Progress bar
        self.progress = QtWidgets.QProgressBar(self)
        self.progress.setMaximum(100)
        right_sidebar.addWidget(self.progress)
        self.progress.hide()

        # Text region
        self.text_region = QtWidgets.QLabel(self)
        self.text_region.setFrameStyle(QtWidgets.QFrame.Panel
                                       | QtWidgets.QFrame.Sunken)
        self.text_region.setWordWrap(True)
        self.text_region.setMargin(8)
        self.text_region.setText('...')
        right_sidebar.addWidget(self.text_region)
        layout.addLayout(right_sidebar)

        # Launch
        self.setWindowIcon(QtGui.QIcon(os.path.join('icon', 'question.png')))
        self.setLayout(layout)
        self.setAcceptDrops(True)
        self.show()

    def prepare_questioner(self):
        self.sess = gpt2.start_tf_sess()
        gpt2.load_gpt2(self.sess)

    def prepare_captioner(self):
        config = yaml.load(open('config.yaml', 'r'), Loader=yaml.FullLoader)
        checkpoint_path = os.path.join(config['project_root_dir'],
                                       config['checkpoint_path'])
        vocab_file_path = os.path.join(config['project_root_dir'],
                                       config['vocab_file_path'])
        self.captioner = Captioner(self.sess, checkpoint_path, vocab_file_path)

    def load_button_clicked(self):
        if self.questioner_running or self.applying_output:
            print("Can't load an image right now. Questioner is busy.")
        else:
            image_path, _ = QtWidgets.QFileDialog.getOpenFileName(
                self, 'Open file')
            if image_path:
                self.load_image(image_path)

    def load_image(self, image_path):
        pixmap = QtGui.QPixmap(image_path)
        pixmap = pixmap.scaled(500, 500, QtCore.Qt.KeepAspectRatio)
        self.viewing_region.setPixmap(pixmap)
        self.text_region.setText('Questioner is working.')
        self.adjustSize()

        self.questioner_running = True
        worker = Worker(self.run_questioner, image_path)
        worker.signals.finished.connect(self.questioner_finished)
        worker.signals.error.connect(self.questioner_failed)
        worker.signals.result.connect(self.apply_questioner_output)
        self.threadpool.start(worker)

    def run_questioner(self, image_path):
        global graph
        with graph.as_default():  # this is run on a separate thread
            caption = self.captioner.caption(image_path)
            questions = gpt2_gen_questions(self.sess,
                                           caption,
                                           nsamples=1,
                                           temperature=0.7)
            return questions[0] if len(questions) > 0 else ''

    def questioner_finished(self):
        self.questioner_running = False

    def questioner_failed(self, e):
        print(e)

    def apply_questioner_output(self, question):
        self.applying_output = True
        if len(question) > 0:
            self.text_region.setText(question)
            if self.tts:
                self.progress.show()
                self.tts.speak(question, self.tts_callback)
                self.progress.hide()
        self.applying_output = False

    def tts_callback(self, i, seq_len, batch_size, gen_rate):
        percentage = i * 100 / seq_len
        self.progress.setValue(percentage)

    def dragEnterEvent(self, evt):
        if evt.mimeData().hasUrls:
            evt.accept()
        else:
            evt.ignore()

    def dragMoveEvent(self, evt):
        if evt.mimeData().hasUrls:
            evt.accept()
        else:
            evt.ignore()

    def dropEvent(self, evt):
        if evt.mimeData().hasUrls \
                and not self.questioner_running \
                and not self.applying_output:
            evt.setDropAction(QtCore.Qt.CopyAction)
            evt.accept()
            for url in evt.mimeData().urls():
                if op_sys == 'Darwin':
                    image_path = str(
                        NSURL.URLWithString_(str(
                            url.toString())).filePathURL().path())
                else:
                    image_path = str(url.toLocalFile())
            self.load_image(image_path)
        else:
            evt.ignore()