コード例 #1
0
    def test_has_access_key(self):
        c = PollyCredential('ap-northeast-1')
        self.assertFalse(c.has_access_key())

        c = PollyCredential('ap-northeast-1', aws_access_key_id='abc')
        self.assertFalse(c.has_access_key())

        c = PollyCredential('ap-northeast-1',
                            aws_access_key_id='abc',
                            aws_secret_access_key='xyz')
        self.assertTrue(c.has_access_key())
コード例 #2
0
    def test_error_with_too_long_text(self):
        cred = PollyCredential('ap-northeast-1')
        self.c.auth(cred)

        text = 'a' * (PollyClient.MAX_TEXT_LENGTH + 1)

        # CloudTTSError is raised with too long text
        self.assertRaises(CloudTTSError, lambda: self.c.tts(text=text))
コード例 #3
0
    def test_acceptable_text_length(self):
        cred = PollyCredential('ap-northeast-1')
        self.c.auth(cred)

        text = 'a' * PollyClient.MAX_TEXT_LENGTH

        # raise TypeError not to call API and
        # to make sure MAX_TEXT_LENGTH works
        self.assertRaises(TypeError, lambda: self.c.tts(
            text=text,
            voice_config=True,
        ))
コード例 #4
0
    def test_error_with_too_long_ssml(self):
        cred = PollyCredential('ap-northeast-1')
        self.c.auth(cred)

        text = 'a' * PollyClient.MAX_TEXT_LENGTH

        # raise TypeError not to call API and
        # to make sure MAX_TEXT_LENGTH works
        ssml = '<speak>{}</speak>'.format(text)
        self.assertRaises(TypeError, lambda: self.c.tts(
            ssml=ssml,
            voice_config=True,
        ))

        # CloudTTSError is raised with too long ssml
        ssml = '<speak>{}</speak>'.format(text + 'a')
        self.assertRaises(CloudTTSError, lambda: self.c.tts(ssml=ssml))
コード例 #5
0
    def test_control_ssml_length_with_text(self):
        cred = PollyCredential('ap-northeast-1')
        self.c.auth(cred)

        text = 'a' * PollyClient.MAX_TEXT_LENGTH
        ssml = '<speak><break>{}</speak>'.format(text)

        # '<break>' is couted and CloudTTSError is raised
        self.assertRaises(CloudTTSError, lambda: self.c.tts(ssml=ssml))

        # 'text' is used to count characters
        #
        # raise TypeError not to call API and
        # to make sure MAX_TEXT_LENGTH works
        self.assertRaises(
            TypeError, lambda: self.c.tts(
                text=text,
                ssml=ssml,
                voice_config=True,
            ))
コード例 #6
0
ファイル: sample.py プロジェクト: setomits/cloudtts
def _polly():
    cred = PollyCredential(
        aws_access_key_id='XXXXXXXXXXXXXXXXXXXX',
        aws_secret_access_key='YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY',
        region_name='ap-northeast-1')
    c = PollyClient(cred)

    # English US
    audio = c.tts('Hi there, it is too hot today.', voice_config=enVC)
    with open('polly_hot_en.mp3', 'wb') as f:
        f.write(audio)

    # English US with SSML
    ssml = '<speak>Hi there,<break time="1s" /> it is too hot today.</speak>'
    audio = c.tts(ssml=ssml, voice_config=enVC)
    with open('polly_hot_en_ssml.mp3', 'wb') as f:
        f.write(audio)

    # Japanese
    c.tts('今日はすごく暑いですね。', voice_config=jaVC)
    with open('polly_hot_ja.mp3', 'wb') as f:
        f.write(audio)
コード例 #7
0
    def test_error_without_data(self):
        cred = PollyCredential('ap-northeast-1')
        self.c.auth(cred)

        self.assertRaises(ValueError, lambda: self.c.tts())