This commit is contained in:
Chris McCord 2023-03-09 12:38:22 -05:00
parent 0c8a1ccac0
commit 742066c102
8 changed files with 29 additions and 7 deletions

View file

@ -10,7 +10,7 @@ defmodule LiveBeats.Audio do
{data, 0} = System.cmd("ffmpeg", args)
{ss, Nx.Serving.batched_run(WhisperServing, Nx.from_binary(data, :f32))}
end,
timeout: :infinity, max_concurrency: 2
timeout: :infinity, max_concurrency: 4
)
|> Enum.map(fn {:ok, {ss, %{results: [%{text: text}]}}} -> func.(ss, text) end)
end

View file

@ -235,7 +235,7 @@ defmodule LiveBeats.MediaLibrary do
segments =
LiveBeats.Audio.speech_to_text(song.mp3_filepath, 20.0, fn ss, text ->
segment = %TextSegment{start_time: ss, text: text}
broadcast!(user.id, %Events.SpeechToText{song_id: song.id, segment: segment})
broadcast!(user.id, %Events.SpeechToText{song_id: song.id, segment: %{segment | in_progress?: true}})
segment
end)

View file

@ -4,5 +4,6 @@ defmodule LiveBeats.MediaLibrary.TextSegment do
embedded_schema do
field :start_time, :float
field :text, :string
field :in_progress?, :boolean, virtual: true, default: false
end
end

View file

@ -45,7 +45,7 @@ defmodule LiveBeats.MP3Stat do
attrib =
case tag_info["COMM"] do
{_, _, info} -> info
{_, _, info} -> String.trim_leading(info, "//")
_ -> nil
end

View file

@ -305,6 +305,15 @@ defmodule LiveBeatsWeb.CoreComponents do
)
end
def fade_in(js \\ %JS{}, id) do
JS.show(js,
to: "##{id}",
time: 1000,
display: "inline-block",
transition: {"ease-out duration-1000", "opacity-0", "opacity-100"}
)
end
def hide(js \\ %JS{}, selector) do
JS.hide(js,
to: selector,
@ -597,7 +606,7 @@ defmodule LiveBeatsWeb.CoreComponents do
phx-click={@row_click && @row_click.(row)}
class={
col[:class!] ||
"px-6 py-3 whitespace-nowrap text-sm font-medium text-gray-900 #{if i == 0, do: "max-w-0 w-full"} #{col[:class]}"
"px-6 py-3 whitespace-nowrap text-sm font-medium text-gray-900 #{col[:class]}"
}
>
<div class="flex items-center space-x-3 lg:pl-2">

View file

@ -60,6 +60,18 @@ defmodule LiveBeatsWeb.ProfileLive do
total_count={@presences_count}
/>
<div id={"speech-#{@active_song_id}"} phx-update="stream" class="mt-6 px-6 max-h-60 overflow-y-scroll">
<div
:for={{id, segment} <- @streams.speech_segments}
id={id}
class={segment.in_progress? && "hidden"}
phx-mounted={segment.in_progress? && fade_in(id)}
>
<span class="text-gray-400">[<%= MP3Stat.to_mmss(trunc(segment.start_time)) %>]</span>
<%= segment.text %>
</div>
</div>
<div id="dialogs" phx-update="stream">
<%= for {_id, song} <- if(@owns_profile?, do: @streams.songs, else: []), id = "delete-modal-#{song.id}" do %>
<.modal
@ -165,7 +177,7 @@ defmodule LiveBeatsWeb.ProfileLive do
songs_count: Enum.count(songs)
)
|> stream(:songs, songs)
|> stream(:speech_segments, speech_segments, dom_id: &"ss-#{&1.start_time}")
|> stream(:speech_segments, speech_segments, dom_id: &"ss-#{trunc(&1.start_time)}")
|> assign_presences()
{:ok, socket, temporary_assigns: [presences: %{}]}

View file

@ -33,7 +33,7 @@ defmodule LiveBeats.MixProject do
defp deps do
[
{:phoenix, "~> 1.7.1"},
{:phoenix_live_view, github: "phoenixframework/phoenix_live_view", override: true},
{:phoenix_live_view, "~> 0.18.17"},
{:phoenix_live_dashboard, "~> 0.7.2"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},

View file

@ -36,7 +36,7 @@
"phoenix_html": {:hex, :phoenix_html, "3.3.1", "4788757e804a30baac6b3fc9695bf5562465dd3f1da8eb8460ad5b404d9a2178", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "bed1906edd4906a15fd7b412b85b05e521e1f67c9a85418c55999277e553d0d3"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.7.2", "97cc4ff2dba1ebe504db72cb45098cb8e91f11160528b980bd282cc45c73b29c", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.3", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "0e5fdf063c7a3b620c566a30fcf68b7ee02e5e46fe48ee46a6ec3ba382dc05b7"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.4.0", "4fe222c0be55fdc3f9c711e24955fc42a7cd9b7a2f5f406f2580a567c335a573", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "bebf0fc2d2113b61cb5968f585367234b7b4c21d963d691de7b4b2dc6cdaae6f"},
"phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "f397224a39d6d10e5a4fcbbd9363f9f87e5121c9", []},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.18.17", "74938b02f3c531bed3f87fe1ea39af6b5b2d26ab1405e77e76b8ef5df9ffa8a1", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.15 or ~> 1.7.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.3", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f4b5710e19a29b8dc93b7af4bab4739c067a3cb759af01ffc3057165453dce38"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
"phoenix_template": {:hex, :phoenix_template, "1.0.1", "85f79e3ad1b0180abb43f9725973e3b8c2c3354a87245f91431eec60553ed3ef", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "157dc078f6226334c91cb32c1865bf3911686f8bcd6bcff86736f6253e6993ee"},
"plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"},