Skip to content

Commit

Permalink
refactor: remove unused audio component/endpoint
Browse files Browse the repository at this point in the history
Nothing seems to be calling this endpoint in production, and the only
reference to it in the code is this `Audio` component, which itself is
not imported anywhere.

Since this was the only case where we sent Polly requests using plain
text instead of SSML, the parameter for text type can also be removed.
  • Loading branch information
digitalcora committed Aug 19, 2024
1 parent e18150e commit fe2909f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 59 deletions.
40 changes: 0 additions & 40 deletions assets/src/components/v2/audio.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions lib/screens/audio.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ defmodule Screens.Audio do

@type departure_group :: {departure_group_key(), [map()]}

@spec synthesize(String.t(), String.t(), keyword()) :: {:ok, binary()} | :error
def synthesize(ssml_string, text_type, log_meta) do
@spec synthesize(String.t(), keyword()) :: {:ok, binary()} | :error
def synthesize(ssml_string, log_meta) do
result =
ssml_string
|> ExAws.Polly.synthesize_speech(lexicon_names: @lexicon_names, text_type: text_type)
|> ExAws.Polly.synthesize_speech(lexicon_names: @lexicon_names, text_type: "ssml")
|> ExAws.request()

case result do
Expand Down
2 changes: 1 addition & 1 deletion lib/screens_web/controllers/audio_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule ScreensWeb.AudioController do
template_assigns <- Screens.Audio.from_api_data(data, screen_id),
ssml <- render_ssml(template_assigns),
{:ok, audio_data} <-
Screens.Audio.synthesize(ssml, "ssml", screen_id: screen_id, is_screen: is_screen) do
Screens.Audio.synthesize(ssml, screen_id: screen_id, is_screen: is_screen) do
send_audio(conn, {:binary, audio_data}, disposition)
else
_ -> send_fallback_audio(conn, is_screen, screen_id, disposition)
Expand Down
12 changes: 1 addition & 11 deletions lib/screens_web/controllers/v2/audio_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,10 @@ defmodule ScreensWeb.V2.AudioController do
end
end

def text_to_speech(conn, %{"text" => text}) do
case Screens.Audio.synthesize(text, "text", is_screen: false) do
{:ok, audio_data} ->
send_download(conn, {:binary, audio_data}, filename: "readout.mp3", disposition: :inline)

:error ->
not_found(conn)
end
end

defp readout(conn, screen_id, real_screen?, disposition) do
screen_id
|> fetch_ssml()
|> Screens.Audio.synthesize("ssml", screen_id: screen_id, is_screen: real_screen?)
|> Screens.Audio.synthesize(screen_id: screen_id, is_screen: real_screen?)
|> case do
{:ok, audio_data} ->
send_download(conn, {:binary, audio_data},
Expand Down
4 changes: 0 additions & 4 deletions lib/screens_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,8 @@ defmodule ScreensWeb.Router do
pipe_through [:redirect_prod_http, :browser, :api]

get "/:id/readout.mp3", AudioController, :show

get "/:id/volume", AudioController, :show_volume

get "/:id/debug", AudioController, :debug

get "/text_to_speech/:text", AudioController, :text_to_speech
end
end

Expand Down

0 comments on commit fe2909f

Please sign in to comment.