Skip to content

Commit

Permalink
CR amends
Browse files Browse the repository at this point in the history
  • Loading branch information
thelgason committed Mar 7, 2024
1 parent fdf9ac6 commit ca0d3fe
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pypy/
pypy*
cpython*/
venv
.python-version

# Installer logs
pip-log.txt
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 1 addition & 1 deletion src/icespeak/tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _setup_voices() -> tuple[VoicesT, ServicesT]:
for service in services:
_LOG.debug("Loading voices from service: %s", service)
if not service.available:
_LOG.info("Voices from service %s not availble.", service)
_LOG.info("Voices from service %s not available.", service)
continue
for voice, info in service.voices.items():
# Info about each voice
Expand Down
6 changes: 4 additions & 2 deletions src/icespeak/voices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from pydantic import BaseModel, Field

from icespeak.settings import Keys, MAX_SPEED, MIN_SPEED, SETTINGS, TextFormats
from icespeak.settings import MAX_SPEED, MIN_SPEED, SETTINGS, Keys, TextFormats
from icespeak.transcribe import DefaultTranscriber

if TYPE_CHECKING:
Expand Down Expand Up @@ -125,5 +125,7 @@ def load_api_keys(self) -> None:
raise NotImplementedError

@abstractmethod
def text_to_speech(self, text: str, options: TTSOptions, keys_override: Keys | None = None) -> Path:
def text_to_speech(
self, text: str, options: TTSOptions, keys_override: Keys | None = None
) -> Path:
raise NotImplementedError
10 changes: 6 additions & 4 deletions src/icespeak/voices/aws_polly.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import boto3

from icespeak.settings import API_KEYS, Keys, SETTINGS
from icespeak.settings import API_KEYS, SETTINGS, AWSPollyKey, Keys

from . import BaseVoice, ModuleAudioFormatsT, ModuleVoicesT, TTSOptions

Expand Down Expand Up @@ -86,12 +86,14 @@ def load_api_keys(self):
)

@override
def text_to_speech(self, text: str, options: TTSOptions, keys_override: Keys | None = None):
def text_to_speech(
self, text: str, options: TTSOptions, keys_override: Keys | None = None
):
if keys_override and keys_override.aws:
_LOG.info(f"Using overridden AWS keys")
_LOG.debug("Using overridden AWS keys")
client = self._create_client(keys_override.aws)
else:
_LOG.info(f"Using default AWS keys")
_LOG.debug("Using default AWS keys")
client = self._aws_client
# Special preprocessing for SSML markup
if options.text_format == "ssml":
Expand Down
10 changes: 6 additions & 4 deletions src/icespeak/voices/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import azure.cognitiveservices.speech as speechsdk

from icespeak.settings import API_KEYS, Keys, SETTINGS
from icespeak.settings import API_KEYS, SETTINGS, Keys
from icespeak.transcribe import DefaultTranscriber, strip_markup

from . import BaseVoice, ModuleAudioFormatsT, ModuleVoicesT, TTSOptions
Expand Down Expand Up @@ -179,13 +179,15 @@ def load_api_keys(self):
AzureVoice.AZURE_REGION = API_KEYS.azure.region.get_secret_value()

@override
def text_to_speech(self, text: str, options: TTSOptions, keys_override: Keys | None = None):
def text_to_speech(
self, text: str, options: TTSOptions, keys_override: Keys | None = None
):
if keys_override and keys_override.azure:
_LOG.info(f"Using overridden Azure keys")
_LOG.debug("Using overridden Azure keys")
subscription = keys_override.azure.key
region = keys_override.azure.region
else:
_LOG.info(f"Using default Azure keys")
_LOG.debug("Using default Azure keys")
subscription = API_KEYS.azure.key
region = API_KEYS.azure.region
speech_conf = speechsdk.SpeechConfig(subscription=subscription, region=region)
Expand Down
6 changes: 4 additions & 2 deletions src/icespeak/voices/tiro.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import requests

from icespeak.settings import Keys, SETTINGS
from icespeak.settings import SETTINGS, Keys
from icespeak.transcribe import strip_markup

from . import BaseVoice, ModuleAudioFormatsT, ModuleVoicesT, TTSOptions
Expand Down Expand Up @@ -70,7 +70,9 @@ def load_api_keys(self):
pass

@override
def text_to_speech(self, text: str, options: TTSOptions, keys_override: Keys | None = None):
def text_to_speech(
self, text: str, options: TTSOptions, keys_override: Keys | None = None
):
# TODO: Tiro's API supports a subset of SSML tags
# See https://tts.tiro.is/#tag/speech/paths/~1v0~1speech/post

Expand Down
6 changes: 3 additions & 3 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def test_greynirssmlparser():
# -------------------------
# Test voice engine specific transcription

assert "Dora" in VOICES
# Gudrun, the default voice, and Dora don't spell things the same
gp2 = GreynirSSMLParser("Dora")
assert "Karl" in VOICES
# Gudrun, the default voice, and Karl don't spell things the same
gp2 = GreynirSSMLParser("Karl")
alphabet = "aábcdðeéfghiíjklmnoópqrstuúvwxyýþæöz"
n1 = gp.transcribe(gssml(alphabet, type="spell"))
n2 = gp2.transcribe(gssml(alphabet, type="spell"))
Expand Down

0 comments on commit ca0d3fe

Please sign in to comment.