Skip to content

Sourcery refactored master branch #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion STT.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def read(self, file_name, language=__NOT_DEFINED):

if not file_name:
raise ValueError('Expected file name')
if not (".flac" in file_name):
if ".flac" not in file_name:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SpeechToText.read refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

raise ValueError('Expected .flac file')

if language == self.__NOT_DEFINED:
Expand Down
12 changes: 8 additions & 4 deletions TTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def __try_detect_language(self, target_language):
return self.__DEFAULT_VOICE

all_voices = self.list_voices()
for voice in all_voices['voices']:
if target_language in voice['language']:
return voice['name']
return self.__DEFAULT_VOICE
return next(
(
voice['name']
for voice in all_voices['voices']
if target_language in voice['language']
),
self.__DEFAULT_VOICE,
)
Comment on lines -28 to +35
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TextToSpeech.__try_detect_language refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)


def speech(self, text, file_name=__NOT_DEFINED,
voice=__NOT_DEFINED, language=__NOT_DEFINED, play_after=True):
Expand Down
12 changes: 8 additions & 4 deletions Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ def list_languages(self):

def search_language_code(self, language_name):
all_languages = self.list_languages()
for language in all_languages['languages']:
if language['language_name'].lower() == language_name.lower():
return language['language']
return None
return next(
(
language['language']
for language in all_languages['languages']
if language['language_name'].lower() == language_name.lower()
),
None,
)
Comment on lines -24 to +31
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Translator.search_language_code refactored with the following changes:

  • Use the built-in function next instead of a for-loop (use-next)


def translate(self, text, source, target):
self.__validate()
Expand Down