예제 #1
0
    def _generate_audio_file(self):
        """
        Generic method used as a Callback in TTSModule
            - must provided the audio file and write it on the disk

        .. raises:: FailToLoadSoundFile
        """

        payload = self.get_payload(self.voice, self.words)

        # getting the mp3
        r = requests.get(TTS_URL,
                         params=payload,
                         stream=True,
                         timeout=TTS_TIMEOUT_SEC)
        content_type = r.headers['Content-Type']

        logger.debug(
            "Voxygen : Trying to get url: %s response code: %s and content-type: %s",
            r.url, r.status_code, content_type)

        if r.status_code == requests.codes.ok and content_type == TTS_CONTENT_TYPE:
            FileManager.write_in_file(self.file_path, r.content)
        else:
            logger.debug(
                "Unable to get a valid audio file. Returned code: %s" %
                r.status_code)
예제 #2
0
파일: acapela.py 프로젝트: plfort/kalliope
    def _generate_audio_file(self):
        """
        Generic method used as a Callback in TTSModule
            - must provided the audio file and write it on the disk

        .. raises:: FailToLoadSoundFile
        """
        # Prepare payload
        payload = self.get_payload()

        # Get the mp3 URL from the page
        url = Acapela.get_audio_link(TTS_URL, payload)

        # getting the mp3
        r = requests.get(url,
                         params=payload,
                         stream=True,
                         timeout=TTS_TIMEOUT_SEC)
        content_type = r.headers['Content-Type']

        logger.debug(
            "Acapela : Trying to get url: %s response code: %s and content-type: %s",
            r.url, r.status_code, content_type)
        # Verify the response status code and the response content type
        if r.status_code != requests.codes.ok or content_type != TTS_CONTENT_TYPE:
            raise FailToLoadSoundFile(
                "Acapela : Fail while trying to remotely access the audio file"
            )

        # OK we get the audio we can write the sound file
        FileManager.write_in_file(self.file_path, r.content)
예제 #3
0
    def get_audio(file_path,
                  cache,
                  payload,
                  url,
                  content_type_expected=TTS_CONTENT_TYPE,
                  timeout_expected=TTS_TIMEOUT_SEC):
        if not cache or not os.path.exists(
                file_path) or FileManager.file_is_empty(file_path):

            r = requests.get(url,
                             params=payload,
                             stream=True,
                             timeout=timeout_expected)

            content_type = r.headers['Content-Type']
            logger.debug(
                "Trying to get url: %s response code: %s and content-type: %s",
                r.url, r.status_code, content_type)

            try:
                if r.status_code == requests.codes.ok and content_type == content_type_expected:
                    return FileManager.write_in_file(file_path, r.content)
                else:
                    return False
            except IOError as e:
                logger.error("I/O error(%s): %s", e.errno, e.strerror)
            except ValueError:
                logger.error("Could not convert data to an integer.")
            except:
                logger.error("Unexpected error: %s", sys.exc_info()[0])
        else:
            return True