diff --git a/lib/screens/audio.ex b/lib/screens/audio.ex index fe3ef8c82..8c1599a1a 100644 --- a/lib/screens/audio.ex +++ b/lib/screens/audio.ex @@ -20,7 +20,8 @@ defmodule Screens.Audio do @type departure_group :: {departure_group_key(), [map()]} - def synthesize(ssml_string, is_screen, text_type) do + @spec synthesize(String.t(), String.t(), keyword()) :: {:ok, binary()} | :error + def synthesize(ssml_string, text_type, log_meta) do result = ssml_string |> ExAws.Polly.synthesize_speech(lexicon_names: @lexicon_names, text_type: text_type) @@ -30,16 +31,13 @@ defmodule Screens.Audio do {:ok, %{body: audio_data}} -> {:ok, audio_data} - {:error, reason} -> - _ = - if is_screen do - Logger.error("synthesize_ssml_failed #{reason}") - end - + {:error, error} -> + report_error(ssml_string, error, log_meta) :error end end + # used in V1 only def from_api_data( %{ station_name: station_name, @@ -188,4 +186,20 @@ defmodule Screens.Audio do psa_config -> Fetch.fetch_psa(psa_config) end end + + defp report_error(ssml_string, error, meta) do + Logger.error( + "synthesize_ssml_failed string=#{inspect(ssml_string)} error=#{inspect(error)}", + meta + ) + + _ = + if meta[:is_screen] do + Sentry.capture_message("synthesize_ssml_failed", + extra: Enum.into(meta, %{error: error, string: ssml_string}) + ) + end + + nil + end end diff --git a/lib/screens_web/controllers/audio_controller.ex b/lib/screens_web/controllers/audio_controller.ex index dd94b01cd..7060fdaae 100644 --- a/lib/screens_web/controllers/audio_controller.ex +++ b/lib/screens_web/controllers/audio_controller.ex @@ -37,7 +37,8 @@ defmodule ScreensWeb.AudioController do Screens.ScreenData.by_screen_id(screen_id, is_screen, check_disabled: true), template_assigns <- Screens.Audio.from_api_data(data, screen_id), ssml <- render_ssml(template_assigns), - {:ok, audio_data} <- Screens.Audio.synthesize(ssml, is_screen, "ssml") do + {:ok, audio_data} <- + Screens.Audio.synthesize(ssml, "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) diff --git a/lib/screens_web/controllers/v2/audio_controller.ex b/lib/screens_web/controllers/v2/audio_controller.ex index b1e983650..c58ef3a94 100644 --- a/lib/screens_web/controllers/v2/audio_controller.ex +++ b/lib/screens_web/controllers/v2/audio_controller.ex @@ -48,7 +48,7 @@ defmodule ScreensWeb.V2.AudioController do end def text_to_speech(conn, %{"text" => text}) do - case Screens.Audio.synthesize(text, false, "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) @@ -60,7 +60,7 @@ defmodule ScreensWeb.V2.AudioController do defp readout(conn, screen_id, real_screen?, disposition) do screen_id |> fetch_ssml() - |> Screens.Audio.synthesize(real_screen?, "ssml") + |> Screens.Audio.synthesize("ssml", screen_id: screen_id, is_screen: real_screen?) |> case do {:ok, audio_data} -> send_download(conn, {:binary, audio_data},