Skip to content

Commit

Permalink
346 feature make tts optional (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwittstruck authored Sep 23, 2024
1 parent fe90f40 commit 81c8825
Show file tree
Hide file tree
Showing 17 changed files with 174 additions and 80 deletions.
4 changes: 3 additions & 1 deletion lib/qrstorage/qr_codes/qr_code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ defmodule Qrstorage.QrCodes.QrCode do
field :voice, Ecto.Enum, values: @voices
field :hp, :string, virtual: true
field :last_accessed_at, :utc_datetime
field :tts, :boolean, default: false

timestamps()
end
Expand All @@ -59,7 +60,8 @@ defmodule Qrstorage.QrCodes.QrCode do
:deltas,
:dots_type,
:voice,
:hp
:hp,
:tts
])
|> validate_length(:hp, is: 0)
|> scrub_text
Expand Down
5 changes: 5 additions & 0 deletions lib/qrstorage/qr_codes/qr_code_migration_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ SET delete_after_months =
log: :info
)
end

@spec add_tts_to_existing_audio_codes(Ecto.Repo.t()) :: any()
def add_tts_to_existing_audio_codes(repo) do
repo.query!("UPDATE qrcodes SET tts = TRUE WHERE content_type = 'audio'", [], log: :info)
end
end
11 changes: 9 additions & 2 deletions lib/qrstorage/services/qr_code_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ defmodule Qrstorage.Services.QrCodeService do
if RateLimitingService.allow?(qr_code) do
# always add translation and get audio:
case add_translation(qr_code) do
{:error, error_message} -> {:error, error_message}
{:ok, qr_code_with_translation} -> add_tts(qr_code_with_translation)
{:error, error_message} ->
{:error, error_message}

{:ok, qr_code_with_translation} ->
if qr_code.tts do
add_tts(qr_code_with_translation)
else
{:ok, qr_code_with_translation}
end
end
else
{:error, gettext("Rate limit reached.")}
Expand Down
14 changes: 7 additions & 7 deletions lib/qrstorage_web/templates/qr_code/form.html.heex
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

<div class="btn-group mb-3 w-100 d-flex justify-content-between" id="content-type-selector" role="group">
<%= radio_button(:qr_code, :content_type, "text",
<%= radio_button(:qr_code, :content_type, "audio",
class: "btn-check content-type",
autocomplete: "off",
checked: content_group_checked(@changeset, "text")
checked: content_group_checked(@changeset, "audio")
) %>
<label class="btn btn-primary" for="qr_code_content_type_text">Text</label>
<%= radio_button(:qr_code, :content_type, "audio",
<label class="btn btn-primary" for="qr_code_content_type_audio">Übersetzung</label>
<%= radio_button(:qr_code, :content_type, "text",
class: "btn-check content-type",
autocomplete: "off",
checked: content_group_checked(@changeset, "audio")
checked: content_group_checked(@changeset, "text")
) %>
<label class="btn btn-primary" for="qr_code_content_type_audio">Audio</label>
<label class="btn btn-primary" for="qr_code_content_type_text">Text</label>
<%= radio_button(:qr_code, :content_type, "recording",
class: "btn-check content-type",
autocomplete: "off",
checked: content_group_checked(@changeset, "recording")
) %>
<label class="btn btn-primary" for="qr_code_content_type_recording">Recording</label>
<label class="btn btn-primary" for="qr_code_content_type_recording">Aufnahme</label>
<%= radio_button(:qr_code, :content_type, "link",
class: "btn-check content-type",
autocomplete: "off",
Expand Down
4 changes: 3 additions & 1 deletion lib/qrstorage_web/templates/qr_code/form_audio.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
</div>
</div>
<div class="form-group">
<%= label(f, :language, gettext("audio language")) %>
<%= label(f, :language, gettext("Target language")) %>
<%= select(f, :language, translated_languages_for_select(), class: "form-control") %>
<%= render("settings/_settings_tts.html", f: f) %>

<%= error_tag(f, :language) %>
<p class="form-text text-muted"><%= gettext("Audio Text to Speech via 3rd party") %></p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<br/>
<%= label(@f, :tts, gettext("TTS")) %>
<div class="form-check form-switch">
<%= checkbox(@f, :tts, class: "form-control form-check-input") %>
</div>
6 changes: 3 additions & 3 deletions lib/qrstorage_web/templates/qr_code/show.html.heex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= if (@qr_code.content_type == :audio && !@qr_code.hide_text) do %>
<%= if (@qr_code.content_type == :audio && (!@qr_code.hide_text || !@qr_code.tts)) do %>
<strong><%= gettext("Text") %></strong>
<br />
<div class="text-box">
Expand Down Expand Up @@ -28,7 +28,7 @@
<p><%= @qr_code.text %></p>
<% end %>

<%= if @qr_code.content_type == :audio do %>
<%= if @qr_code.content_type == :audio && @qr_code.tts do %>
<div class="row">
<div class="col-md-12">
<%= render("partials/_player.html", conn: @conn, qr_code: @qr_code) %>
Expand All @@ -43,7 +43,7 @@
</div>
<%= if @qr_code.content_type == :audio do %>
<div class="col-6">
<strong><%= gettext("Audio Language") %></strong> <br />
<strong><%= gettext("Language") %></strong> <br />
<%= Gettext.dgettext(QrstorageWeb.Gettext, "languages", Atom.to_string(@qr_code.language)) %>
<%= if show_translation_origin_for_hidden_text(@qr_code) do %>
<br />
Expand Down
2 changes: 1 addition & 1 deletion lib/qrstorage_web/views/qr_code_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule QrstorageWeb.QrCodeView do
# Without changes, we default to show the content group of the type text:
if changeset.changes == %{} do
case content_group do
"text" -> true
"audio" -> true
_ -> false
end
else
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Qrstorage.MixProject do
def project do
[
app: :qrstorage,
version: "0.4.2",
version: "0.4.3",
elixir: "~> 1.11",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
43 changes: 24 additions & 19 deletions priv/gettext/de/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr ""
msgid "Oops, something went wrong! Please check the errors below."
msgstr "Oops, da ist etwas schiefgelaufen. Bitte korrigiere die folgenden Fehler."

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:57
#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:59
#: lib/qrstorage_web/templates/qr_code/form_link.html.heex:47
#: lib/qrstorage_web/templates/qr_code/form_recording.html.heex:45
#: lib/qrstorage_web/templates/qr_code/form_text.html.heex:56
Expand All @@ -38,22 +38,12 @@ msgstr "Erstellen"
msgid "Deletion Date"
msgstr "Löschdatum"

#: lib/qrstorage_web/templates/qr_code/show.html.heex:46
#, elixir-autogen, elixir-format
msgid "Audio Language"
msgstr "Sprachausgabe"

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:37
#, elixir-autogen, elixir-format
msgid "audio language"
msgstr "Sprachausgabe"

#: lib/qrstorage_web/templates/qr_code/settings/_settings_delete_after.html.heex:3
#, elixir-autogen, elixir-format
msgid "delete after"
msgstr "Löschung bei Inaktivität in Monaten"

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:40
#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:42
#, elixir-autogen, elixir-format
msgid "Audio Text to Speech via 3rd party"
msgstr "Für die Sprachausgabe und die Übersetzung kommunizieren wir mit DeepL und ReadSpeaker."
Expand All @@ -66,7 +56,7 @@ msgstr "Gib deinen Text hier ein!"
#: lib/qrstorage_web/templates/qr_code/settings/_settings_hide_text.html.heex:3
#, elixir-autogen, elixir-format
msgid "hide text"
msgstr "Text in Ausgabe verstecken"
msgstr "Text bei Sprachausgabe ausblenden"

#: lib/qrstorage_web/templates/qr_code/download.html.heex:67
#, elixir-autogen, elixir-format
Expand Down Expand Up @@ -205,7 +195,7 @@ msgstr "Dieses Tool darf nur in Bildungskontexten genutzt werden. Die Eingabe se
#: lib/qrstorage_web/templates/qr_code/new.html.heex:2
#, elixir-autogen, elixir-format
msgid "Create speaking QR-Codes!"
msgstr "Erstelle sprechende QR-Codes!"
msgstr "Übersetze deinen Text!"

#: lib/qrstorage_web/templates/qr_code/new.html.heex:5
#, elixir-autogen, elixir-format
Expand All @@ -228,8 +218,8 @@ msgstr "Fehler beim Upload der Audio-Datei."
msgid "Error while extracting audio file from plug: Invalid content type"
msgstr "Fehler beim Upload der Audio-Datei."

#: lib/qrstorage/services/qr_code_service.ex:88
#: lib/qrstorage/services/qr_code_service.ex:92
#: lib/qrstorage/services/qr_code_service.ex:95
#: lib/qrstorage/services/qr_code_service.ex:99
#, elixir-autogen, elixir-format
msgid "Qr code recording not extracted"
msgstr "Fehler beim Upload der Audio-Datei."
Expand Down Expand Up @@ -260,8 +250,8 @@ msgstr "Die Seite konnte nicht gefunden werden."
msgid "QR-Code has been deleted?"
msgstr "QR-Codes werden nach Inaktivität und Ablauf der ausgewählten Speicherdauer gelöscht."

#: lib/qrstorage/services/qr_code_service.ex:105
#: lib/qrstorage/services/qr_code_service.ex:109
#: lib/qrstorage/services/qr_code_service.ex:112
#: lib/qrstorage/services/qr_code_service.ex:116
#, elixir-autogen, elixir-format
msgid "Qr code tts not stored"
msgstr ""
Expand All @@ -281,7 +271,22 @@ msgstr "Aufnahmen werden nach 30 Tagen Inaktivität gelöscht."
msgid "Text was automatically translated by DeepL."
msgstr "Der Text wurde automatisch übersetzt von DeepL."

#: lib/qrstorage/services/qr_code_service.ex:58
#: lib/qrstorage/services/qr_code_service.ex:65
#, elixir-autogen, elixir-format
msgid "Rate limit reached."
msgstr "Derzeit können keine QR-Codes erstellt werden. Bitte versuch es später erneut."

#: lib/qrstorage_web/templates/qr_code/show.html.heex:46
#, elixir-autogen, elixir-format
msgid "Language"
msgstr "Sprache"

#: lib/qrstorage_web/templates/qr_code/settings/_settings_tts.html.heex:2
#, elixir-autogen, elixir-format
msgid "TTS"
msgstr "Sprachausgabe aktivieren"

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:37
#, elixir-autogen, elixir-format
msgid "Target language"
msgstr "Zielsprache"
39 changes: 22 additions & 17 deletions priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ msgstr ""
msgid "Oops, something went wrong! Please check the errors below."
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:57
#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:59
#: lib/qrstorage_web/templates/qr_code/form_link.html.heex:47
#: lib/qrstorage_web/templates/qr_code/form_recording.html.heex:45
#: lib/qrstorage_web/templates/qr_code/form_text.html.heex:56
Expand All @@ -37,22 +37,12 @@ msgstr ""
msgid "Deletion Date"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/show.html.heex:46
#, elixir-autogen, elixir-format
msgid "Audio Language"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:37
#, elixir-autogen, elixir-format
msgid "audio language"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/settings/_settings_delete_after.html.heex:3
#, elixir-autogen, elixir-format
msgid "delete after"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:40
#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:42
#, elixir-autogen, elixir-format
msgid "Audio Text to Speech via 3rd party"
msgstr ""
Expand Down Expand Up @@ -227,8 +217,8 @@ msgstr ""
msgid "Error while extracting audio file from plug: Invalid content type"
msgstr ""

#: lib/qrstorage/services/qr_code_service.ex:88
#: lib/qrstorage/services/qr_code_service.ex:92
#: lib/qrstorage/services/qr_code_service.ex:95
#: lib/qrstorage/services/qr_code_service.ex:99
#, elixir-autogen, elixir-format
msgid "Qr code recording not extracted"
msgstr ""
Expand Down Expand Up @@ -259,8 +249,8 @@ msgstr ""
msgid "QR-Code has been deleted?"
msgstr ""

#: lib/qrstorage/services/qr_code_service.ex:105
#: lib/qrstorage/services/qr_code_service.ex:109
#: lib/qrstorage/services/qr_code_service.ex:112
#: lib/qrstorage/services/qr_code_service.ex:116
#, elixir-autogen, elixir-format
msgid "Qr code tts not stored"
msgstr ""
Expand All @@ -280,7 +270,22 @@ msgstr ""
msgid "Text was automatically translated by DeepL."
msgstr ""

#: lib/qrstorage/services/qr_code_service.ex:58
#: lib/qrstorage/services/qr_code_service.ex:65
#, elixir-autogen, elixir-format
msgid "Rate limit reached."
msgstr ""

#: lib/qrstorage_web/templates/qr_code/show.html.heex:46
#, elixir-autogen, elixir-format
msgid "Language"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/settings/_settings_tts.html.heex:2
#, elixir-autogen, elixir-format
msgid "TTS"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:37
#, elixir-autogen, elixir-format
msgid "Target language"
msgstr ""
39 changes: 22 additions & 17 deletions priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr ""
msgid "Oops, something went wrong! Please check the errors below."
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:57
#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:59
#: lib/qrstorage_web/templates/qr_code/form_link.html.heex:47
#: lib/qrstorage_web/templates/qr_code/form_recording.html.heex:45
#: lib/qrstorage_web/templates/qr_code/form_text.html.heex:56
Expand All @@ -38,22 +38,12 @@ msgstr ""
msgid "Deletion Date"
msgstr "Deleted"

#: lib/qrstorage_web/templates/qr_code/show.html.heex:46
#, elixir-autogen, elixir-format
msgid "Audio Language"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:37
#, elixir-autogen, elixir-format
msgid "audio language"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/settings/_settings_delete_after.html.heex:3
#, elixir-autogen, elixir-format
msgid "delete after"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:40
#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:42
#, elixir-autogen, elixir-format
msgid "Audio Text to Speech via 3rd party"
msgstr "We use DeepL and ReadSpeaker for text to speech and for translations."
Expand Down Expand Up @@ -228,8 +218,8 @@ msgstr ""
msgid "Error while extracting audio file from plug: Invalid content type"
msgstr ""

#: lib/qrstorage/services/qr_code_service.ex:88
#: lib/qrstorage/services/qr_code_service.ex:92
#: lib/qrstorage/services/qr_code_service.ex:95
#: lib/qrstorage/services/qr_code_service.ex:99
#, elixir-autogen, elixir-format
msgid "Qr code recording not extracted"
msgstr ""
Expand Down Expand Up @@ -260,8 +250,8 @@ msgstr ""
msgid "QR-Code has been deleted?"
msgstr ""

#: lib/qrstorage/services/qr_code_service.ex:105
#: lib/qrstorage/services/qr_code_service.ex:109
#: lib/qrstorage/services/qr_code_service.ex:112
#: lib/qrstorage/services/qr_code_service.ex:116
#, elixir-autogen, elixir-format
msgid "Qr code tts not stored"
msgstr ""
Expand All @@ -281,7 +271,22 @@ msgstr ""
msgid "Text was automatically translated by DeepL."
msgstr "Text was automatically translated by DeepL."

#: lib/qrstorage/services/qr_code_service.ex:58
#: lib/qrstorage/services/qr_code_service.ex:65
#, elixir-autogen, elixir-format
msgid "Rate limit reached."
msgstr ""

#: lib/qrstorage_web/templates/qr_code/show.html.heex:46
#, elixir-autogen, elixir-format
msgid "Language"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/settings/_settings_tts.html.heex:2
#, elixir-autogen, elixir-format
msgid "TTS"
msgstr ""

#: lib/qrstorage_web/templates/qr_code/form_audio.html.heex:37
#, elixir-autogen, elixir-format
msgid "Target language"
msgstr ""
Loading

0 comments on commit 81c8825

Please sign in to comment.