Skip to content

Commit

Permalink
v35.13 fixed google cloud texttospeech integration
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Oct 13, 2023
1 parent 1593a40 commit 4d84dcb
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion UniqueBibleAppVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35.12
35.13
3 changes: 3 additions & 0 deletions latest_changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes in 35.13:
* Fixed google-cloud text-to-speech integration.

Changes in 35.12:
* exit w3m without user confirmation

Expand Down
14 changes: 7 additions & 7 deletions patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,6 @@
(33.96, "file", "gui/WorkSpace.py")
(33.96, "file", "gui/YouTubePopover.py")
(33.96, "file", "startup/nonGui.py")
(33.96, "file", "util/CrossPlatform.py")
(33.98, "file", "gui/MenuItems.py")
(34.04, "file", "htmlResources/material/action/terminal/materialiconsoutlined/48dp/2x/outline_terminal_black_48dp.png")
(34.05, "file", "plugins/menu/Terminal.py")
Expand All @@ -1315,7 +1314,6 @@
(34.20, "file", "gui/PlaylistUI.py")
(34.23, "file", "gui/ConfigFlagsWindow.py")
(34.23, "file", "util/RemoteCliMainWindow.py")
(34.23, "file", "util/TextEditorUtility.py")
(34.26, "file", "install/module.py")
(34.26, "file", "util/text_editor_checkup.py")
(34.27, "file", "htmlResources/material/action/question_answer/materialiconsoutlined/48dp/2x/outline_question_answer_black_48dp.png")
Expand Down Expand Up @@ -1382,14 +1380,16 @@
(35.05, "file", "gui/Worker.py")
(35.06, "file", "plugins/menu/Bible Chat.py")
(35.09, "file", "db/BiblesSqlite.py")
(35.09, "file", "util/TextCommandParser.py")
(35.10, "file", "plugins/startup/highlightActiveVerse.py")
(35.10, "file", "util/ConfigUtil.py")
(35.10, "file", "util/terminal_system_command_prompt.py")
(35.12, "file", "plugins/terminal/generate reference table from copied text.py")
(35.12, "file", "plugins/terminal/generate reference table from latest content.py")
(35.12, "file", "plugins/terminal/open html content with w3m.py")
(35.12, "file", "util/LocalCliHandler.py")
(35.12, "file", "patches.txt")
(35.12, "file", "UniqueBibleAppVersion.txt")
(35.12, "file", "latest_changes.txt")
(35.13, "file", "util/CrossPlatform.py")
(35.13, "file", "util/LocalCliHandler.py")
(35.13, "file", "util/TextCommandParser.py")
(35.13, "file", "util/TextEditorUtility.py")
(35.13, "file", "patches.txt")
(35.13, "file", "UniqueBibleAppVersion.txt")
(35.13, "file", "latest_changes.txt")
7 changes: 5 additions & 2 deletions util/CrossPlatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def saveCloudTTSAudio(self, inputText, languageCode, filename=""):
if not moduleInstalled:
installmodule("--upgrade google-cloud-texttospeech")
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.path.join(os.getcwd(), "credentials_GoogleCloudTextToSpeech.json")
# Modified from ource: https://cloud.google.com/text-to-speech/docs/create-audio-text-client-libraries#client-libraries-install-python
# Modified from source: https://cloud.google.com/text-to-speech/docs/create-audio-text-client-libraries#client-libraries-install-python
"""Synthesizes speech from the input string of text or ssml.
Make sure to be working in a virtual environment.
Expand All @@ -308,8 +308,11 @@ def saveCloudTTSAudio(self, inputText, languageCode, filename=""):

# Build the voice request, select the language code (e.g. "yue-HK") and the ssml
# voice gender ("neutral")
# Supported language: https://cloud.google.com/speech-to-text/docs/speech-to-text-supported-languages
# Voice: https://cloud.google.com/text-to-speech/docs/voices
# Gener: https://cloud.google.com/text-to-speech/docs/reference/rest/v1/SsmlVoiceGender
voice = texttospeech.VoiceSelectionParams(
language_code=languageCode, ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
language_code=languageCode, ssml_gender=texttospeech.SsmlVoiceGender.SSML_VOICE_GENDER_UNSPECIFIED
)

# Select the type of audio file you want returned
Expand Down
5 changes: 3 additions & 2 deletions util/LocalCliHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, command="John 3:16"):
self.html = "<ref >Unique Bible App</ref>"
self.plainText = "Unique Bible App"
self.setupDialogs()
self.audioPlayer = None
self.command = command
self.dotCommands = self.getDotCommands()
self.addShortcuts()
Expand Down Expand Up @@ -2718,7 +2719,7 @@ def generateImage(self):
with open(imageFile, mode="wb") as pngObj:
pngObj.write(image_data)
if config.terminalEnableTermuxAPI:
config.mainWindow.getCliOutput(f"termux-share {imageFile}")
self.getCliOutput(f"termux-share {imageFile}")
else:
os.system(f"{config.open} {imageFile}")
# error codes: https://platform.openai.com/docs/guides/error-codes/python-library-error-types
Expand Down Expand Up @@ -4079,7 +4080,7 @@ def changemymenu(self):
userInput = prompt(self.inputIndicator, key_bindings=self.prompt_multiline_shared_key_bindings, bottom_toolbar=self.getToolBar(True), enable_system_prompt=True, swap_light_and_dark_colors=Condition(lambda: not config.terminalResourceLinkColor.startswith("ansibright")), style=self.promptStyle, multiline=True, default=default).strip()
if userInput.lower() == config.terminal_cancel_action:
return self.cancelAction()
config.terminalMyMenu = [i.lower().strip() for i in userInput.split("\n") if i.lower().strip() in config.mainWindow.dotCommands]
config.terminalMyMenu = [i.lower().strip() for i in userInput.split("\n") if i.lower().strip() in self.dotCommands]
self.print("config.terminalMyMenu is changed to:")
self.print(config.terminalMyMenu)

Expand Down
8 changes: 5 additions & 3 deletions util/TextCommandParser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8
import glob, pprint
import pydoc
import glob, pprint, traceback, pydoc
import os, re, webbrowser, platform, zipfile, subprocess, config
from datetime import date
from util.VlcUtil import VlcUtil
Expand Down Expand Up @@ -1504,7 +1503,10 @@ def googleTextToSpeech(self, command, source):
if os.path.isfile(audioFile):
self.openMediaPlayer(audioFile, "main", gui=False)
except:
self.parent.displayMessage(config.thisTranslation["message_fail"])
if config.developer:
print(traceback.format_exc())
else:
self.parent.displayMessage(config.thisTranslation["message_fail"])

# Keep the following codes for future reference
# The following method does not work on Windows
Expand Down
2 changes: 1 addition & 1 deletion util/TextEditorUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def saveCloudTTSAudio(self, inputText, languageCode, filename=""):
# Build the voice request, select the language code (e.g. "yue-HK") and the ssml
# voice gender ("neutral")
voice = texttospeech.VoiceSelectionParams(
language_code=languageCode, ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
language_code=languageCode, ssml_gender=texttospeech.SsmlVoiceGender.SSML_VOICE_GENDER_UNSPECIFIED
)

# Select the type of audio file you want returned
Expand Down

0 comments on commit 4d84dcb

Please sign in to comment.