Exemplo n.º 1
0
def getaudio_acapela(text, tts_language='en'):
    """
    Run Acapela Text2Speech and return audio url
    """
    import acapela
    DIRECTORY = settings.MEDIA_ROOT + '/tts/'
    if not tts_language:
        tts_language = 'en'
    tts_acapela = acapela.Acapela(
        settings.ACCOUNT_LOGIN, settings.APPLICATION_LOGIN,
        settings.APPLICATION_PASSWORD, settings.SERVICE_URL,
        settings.QUALITY, DIRECTORY)
    tts_acapela.prepare(
        text, tts_language, settings.ACAPELA_GENDER,
        settings.ACAPELA_INTONATION)
    output_filename = tts_acapela.run()
    audiofile = 'tts/' + output_filename
    return audiofile
Exemplo n.º 2
0
def test_acapela():
    """
    Function to test text to speech
    """
    # Construct
    tts_acapela = acapela.Acapela(ACCOUNT_LOGIN, APPLICATION_LOGIN,
                                  APPLICATION_PASSWORD, SERVICE_URL, QUALITY,
                                  DIRECTORY)

    # General settings for test
    gender = 'W'
    intonation = 'NORMAL'

    # Spanish
    lang = 'ES'
    text = u"Newfies-Dialer es una aplicación de transmisión de voz diseñado y construido para automatizar la entrega de las llamadas telefónicas interactivas a contactos, clientes y público en general."
    tts_acapela.prepare(text, lang, gender, intonation)
    output_filename = tts_acapela.run()
    print "Recorded TTS to %s" % output_filename

    # Portuguese
    lang = 'BR'
    text = u"Newfies-Dialer é um aplicativo de transmissão de voz projetada e construída para automatizar a entrega de telefonemas interativos para contatos, clientes e público em geral."
    tts_acapela.prepare(text, lang, gender, intonation)
    output_filename = tts_acapela.run()
    print "Recorded TTS to %s" % output_filename

    # French
    lang = 'FR'
    text = u"Newfies-Dialer est une application de diffusion vocale conçu et construit pour automatiser la livraison des appels téléphoniques interactifs à des contacts, des clients et le public en général."
    tts_acapela.prepare(text, lang, gender, intonation)
    output_filename = tts_acapela.run()
    print "Recorded TTS to %s" % output_filename

    # English
    lang = 'EN'
    text = "Newfies-Dialer is a voice broadcast application designed and built to automate the delivery of interactive phone calls to contacts, clients and the general public."
    tts_acapela.prepare(text, lang, gender, intonation)
    output_filename = tts_acapela.run()
    print "Recorded TTS to %s" % output_filename
Exemplo n.º 3
0
    def say_something(self, text, directory='/tmp/', in_background=True):
        """It says something using ACAPELA tts

        @param text the string to say
        @param in_background run the process in background
        """
        print("[ICUB][ACAPELA] Downloading the mp3 file...")

        tts_acapela = acapela.Acapela(self.acapela_account_login,
                                      self.acapela_application_login,
                                      self.acapela_application_password,
                                      self.acapela_service_url,
                                      quality='22k',
                                      directory=directory)
        tts_acapela.prepare(text=text,
                            lang='US',
                            gender='M',
                            intonation='NORMAL')
        output_filename = tts_acapela.run()
        print "[ICUB][ACAPELA] Recorded TTS to %s" % output_filename
        subprocess.Popen(["play", "-q", directory + str(output_filename)])
        print "[ICUB][PLAY] reproducing the acapela file"
Exemplo n.º 4
0
    def create(self, request=None, **kwargs):
        """POST method of Answercall API"""
        logger.debug('Answercall API authentication called!')
        auth_result = self._meta.authentication.is_authenticated(request)
        if not auth_result is True:
            raise ImmediateHttpResponse(response=http.HttpUnauthorized())

        logger.debug('Answercall API authorization called!')
        auth_result = self._meta.authorization.is_authorized(request, object)

        logger.debug('Answercall API validation called!')
        errors = self._meta.validation.is_valid(request)

        if not errors:
            logger.debug('Answercall API get called!')

            opt_ALegRequestUUID = request.POST.get('ALegRequestUUID')
            opt_CallUUID = request.POST.get('CallUUID')

            #TODO: If we update the Call to success here we should
            # not do it in hangup url
            obj_callrequest = Callrequest.objects\
                .get(request_uuid=opt_ALegRequestUUID)

            #TODO : use constant
            obj_callrequest.status = 8  # IN-PROGRESS
            obj_callrequest.aleg_uuid = opt_CallUUID
            obj_callrequest.save()

            # check if Voice App
            if obj_callrequest.content_object.__class__.__name__ != 'VoiceApp':
                object_list = []
                logger.error('Error with App type, not a VoiceApp!')
            else:
                data = obj_callrequest.content_object.data
                tts_language = obj_callrequest.content_object.tts_language

                extra_data = obj_callrequest.campaign.extra_data
                if extra_data and len(extra_data) > 1:
                    #check if we have a voice_app_data tag to replace
                    voice_app_data = search_tag_string(extra_data,
                                                       'voice_app_data')
                    if voice_app_data:
                        data = voice_app_data

                if obj_callrequest.content_object.type == 1:
                    #Dial
                    timelimit = obj_callrequest.timelimit
                    callerid = obj_callrequest.callerid
                    gatewaytimeouts = obj_callrequest.timeout
                    gateways = obj_callrequest.content_object.gateway.gateways
                    dial_command = 'Dial timeLimit="%s" ' \
                                   'callerId="%s" ' \
                                   'callbackUrl="%s"' % \
                                   (timelimit,
                                    callerid,
                                    PLIVO_DEFAULT_DIALCALLBACK_URL)
                    number_command = 'Number gateways="%s" ' \
                                     'gatewayTimeouts="%s"' % \
                                     (gateways, gatewaytimeouts)

                    object_list = [{dial_command: {number_command: data}}]
                    logger.debug('Dial command')

                elif obj_callrequest.content_object.type == 2:
                    #PlayAudio
                    object_list = [{'Play': data}]
                    logger.debug('PlayAudio')

                elif obj_callrequest.content_object.type == 3:
                    #Conference
                    object_list = [{'Conference': data}]
                    logger.debug('Conference')

                elif obj_callrequest.content_object.type == 4:
                    #Speak
                    if settings.TTS_ENGINE != 'ACAPELA':
                        object_list = [{'Speak': data}]
                        logger.debug('Speak')
                    else:
                        import acapela
                        DIRECTORY = settings.MEDIA_ROOT + '/tts/'
                        domain = Site.objects.get_current().domain
                        tts_acapela = acapela.Acapela(
                            settings.TTS_ENGINE, settings.ACCOUNT_LOGIN,
                            settings.APPLICATION_LOGIN,
                            settings.APPLICATION_PASSWORD,
                            settings.SERVICE_URL, settings.QUALITY, DIRECTORY)
                        tts_acapela.prepare(data, tts_language,
                                            settings.ACAPELA_GENDER,
                                            settings.ACAPELA_INTONATION)
                        output_filename = tts_acapela.run()

                        audiofile_url = domain + settings.MEDIA_URL +\
                                        'tts/' + output_filename
                        object_list = [{'Play': audiofile_url}]
                        logger.debug('PlayAudio-TTS')
                else:
                    logger.error('Error with Voice App type!')

            obj = CustomXmlEmitter()
            return self.create_response(request,
                                        obj.render(request, object_list))

        else:
            logger.debug('ERROR : ' + str(errors))
            if len(errors):
                if request:
                    desired_format = self.determine_format(request)
                else:
                    desired_format = self._meta.default_format

                serialized = self.serialize(request, errors, desired_format)
                response = http.HttpBadRequest(content=serialized,
                                               content_type=desired_format)
                raise ImmediateHttpResponse(response=response)