From f7b66cab3e0e2d37c8a25df77f1652160dcb12e2 Mon Sep 17 00:00:00 2001 From: Gonzalo Bulnes Guilpain Date: Mon, 1 Jan 2024 20:14:13 -0500 Subject: [PATCH 1/3] refactor: remove unused and duplicate imports --- voice-gen.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/voice-gen.py b/voice-gen.py index 05556aa6..660b8d1f 100755 --- a/voice-gen.py +++ b/voice-gen.py @@ -5,7 +5,6 @@ import re import sys import time -import subprocess from pathlib import Path try: @@ -17,7 +16,6 @@ https://docs.microsoft.com/azure/cognitive-services/speech-service/quickstart-text-to-speech-python for installation instructions. """) - import sys sys.exit(1) From 78988f56913a0da7be45f8c48bc6c4493a3be45e Mon Sep 17 00:00:00 2001 From: Gonzalo Bulnes Guilpain Date: Mon, 1 Jan 2024 20:17:42 -0500 Subject: [PATCH 2/3] refactor: fix missing whitespace after keyword (E275) --- voice-gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/voice-gen.py b/voice-gen.py index 660b8d1f..f5ca4ea3 100755 --- a/voice-gen.py +++ b/voice-gen.py @@ -123,7 +123,7 @@ def main() -> None: speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region) - if not(os.path.isfile(csv_file)): + if not os.path.isfile(csv_file): print("Error: voice file not found") sys.exit(1) From c50e96e603a4762e0ee2c86e3f96c4e5bee2037a Mon Sep 17 00:00:00 2001 From: Gonzalo Bulnes Guilpain Date: Mon, 1 Jan 2024 20:32:43 -0500 Subject: [PATCH 3/3] refactor: use f-strings consitently --- build-checks.py | 14 ++++++++------ voice-gen.py | 6 ++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-checks.py b/build-checks.py index dcfb8fb7..88ba4281 100755 --- a/build-checks.py +++ b/build-checks.py @@ -21,7 +21,7 @@ def checkCSVcolumnCount(): reader = csv.reader(open(f, "r")) for row in reader: if not len(row) == 6: - print("{}: Insufficient columns of data - {}".format(filename, row)) + print(f"{filename}: Insufficient columns of data - {row}") missing_csv_field = True continue @@ -30,6 +30,7 @@ def checkCSVcolumnCount(): else: return 0 + def checkFilenameLengths(): print("SOUNDS: Checking file name lengths ...") invalid_filename_found = False @@ -38,12 +39,12 @@ def checkFilenameLengths(): path = os.path.join(dirpath, fn) if path.split(os.path.sep)[2] == "SYSTEM": if len(os.path.splitext(fn)[0]) > 8: - print("Filename too long for a SYSTEM file: {}".format(path)) + print(f"Filename too long for a SYSTEM file: {path}") invalid_filename_found = True elif path.split(os.path.sep)[2] == "SCRIPTS": continue elif len(os.path.splitext(fn)[0]) > 6: - print("Filename too long for a non-SYSTEM file: {}".format(path)) + print(f"Filename too long for a non-SYSTEM file: {path}") invalid_filename_found = True if invalid_filename_found: @@ -60,7 +61,7 @@ def checkNoZeroByteFiles(): for fn in files: path = os.path.join(root, fn) if os.stat(path).st_size == 0: - print("Zero byte file: {}".format(path)) + print(f"Zero byte file: {path}") zero_byte_file_found = True if zero_byte_file_found: @@ -76,7 +77,7 @@ def validateSoundsJson(): try: json.load(f) except ValueError as err: - print("JSON not valid: {}".format(str(err))) + print(f"JSON not valid: {str(err)}") invalid_json_found = True if invalid_json_found: @@ -84,6 +85,7 @@ def validateSoundsJson(): else: return 0 + def checkForDuplicateStringID(): print("VOICES: Check for duplicate StringIDs ...") duplicate_found = False @@ -111,7 +113,7 @@ def checkForDuplicateStringID(): else: StringID = row[0] if StringID in StringID_count.keys(): - print('{}: {} is duplicated'.format(f, StringID)) + print(f'{f}: {StringID} is duplicated') StringID_count[StringID] = StringID_count[StringID] + 1 duplicate_found = True else: diff --git a/voice-gen.py b/voice-gen.py index f5ca4ea3..b552a85b 100755 --- a/voice-gen.py +++ b/voice-gen.py @@ -179,11 +179,9 @@ def main() -> None: # If failed, show error, remove empty/corrupt file and halt if result.reason == speechsdk.ResultReason.Canceled: cancellation_details = result.cancellation_details - print("Speech synthesis canceled: {}".format( - cancellation_details.reason)) + print(f"Speech synthesis canceled: {cancellation_details.reason}") if cancellation_details.reason == speechsdk.CancellationReason.Error: - print("Error details: {}".format( - cancellation_details.error_details)) + print(f"Error details: {cancellation_details.error_details}") if os.path.isfile(outdir + os.sep + filename): os.remove(outdir + os.sep + filename) sys.exit(1)