From 38d5158773d3c02ff71cbd2fa70d1c8945afff3e Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Mon, 13 Mar 2023 11:37:59 -0400 Subject: [PATCH] Reset --- lib/live_beats/application.ex | 12 ------------ lib/live_beats/audio.ex | 17 ----------------- lib/live_beats/media_library/events.ex | 4 ---- lib/live_beats/media_library/song.ex | 1 - lib/live_beats/media_library/text_segment.ex | 9 --------- lib/live_beats_web/live/profile_live.ex | 15 --------------- mix.exs | 5 +---- ...30308164408_add_speech_segments_to_songs.exs | 9 --------- 8 files changed, 1 insertion(+), 71 deletions(-) delete mode 100644 lib/live_beats/audio.ex delete mode 100644 lib/live_beats/media_library/text_segment.ex delete mode 100644 priv/repo/migrations/20230308164408_add_speech_segments_to_songs.exs diff --git a/lib/live_beats/application.ex b/lib/live_beats/application.ex index 1e93335..7cac791 100644 --- a/lib/live_beats/application.ex +++ b/lib/live_beats/application.ex @@ -10,19 +10,7 @@ defmodule LiveBeats.Application do LiveBeats.MediaLibrary.attach() topologies = Application.get_env(:libcluster, :topologies) || [] - {:ok, whisper} = Bumblebee.load_model({:hf, "openai/whisper-tiny"}) - {:ok, featurizer} = Bumblebee.load_featurizer({:hf, "openai/whisper-tiny"}) - {:ok, tokenizer} = Bumblebee.load_tokenizer({:hf, "openai/whisper-tiny"}) - children = [ - {Nx.Serving, - serving: - Bumblebee.Audio.speech_to_text(whisper, featurizer, tokenizer, - max_new_tokens: 200, - defn_options: [batch_size: 10, compiler: EXLA] - ), - name: WhisperServing, - batch_timeout: 100}, {Cluster.Supervisor, [topologies, [name: LiveBeats.ClusterSupervisor]]}, {Task.Supervisor, name: LiveBeats.TaskSupervisor}, # Start the Ecto repository diff --git a/lib/live_beats/audio.ex b/lib/live_beats/audio.ex deleted file mode 100644 index a986243..0000000 --- a/lib/live_beats/audio.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule LiveBeats.Audio do - def speech_to_text(path, chunk_time \\ 15.0, func) when chunk_time <= 30.0 do - {:ok, stat} = LiveBeats.MP3Stat.parse(path) - - Stream.iterate(0, &(&1 + chunk_time)) - |> Enum.take_while(&(&1 < stat.duration)) - |> Task.async_stream( - fn ss -> - args = ~w(-i #{path} -ac 1 -ar 16k -f f32le -ss #{ss} -t #{chunk_time} -v quiet -) - {data, 0} = System.cmd("ffmpeg", args) - {ss, Nx.Serving.batched_run(WhisperServing, Nx.from_binary(data, :f32))} - end, - timeout: :infinity, max_concurrency: 4 - ) - |> Enum.map(fn {:ok, {ss, %{results: [%{text: text}]}}} -> func.(ss, text) end) - end -end diff --git a/lib/live_beats/media_library/events.ex b/lib/live_beats/media_library/events.ex index 4710f46..724c3ee 100644 --- a/lib/live_beats/media_library/events.ex +++ b/lib/live_beats/media_library/events.ex @@ -22,8 +22,4 @@ defmodule LiveBeats.MediaLibrary.Events do defmodule SongDeleted do defstruct song: nil end - - defmodule SpeechToText do - defstruct song_id: nil, segment: nil - end end diff --git a/lib/live_beats/media_library/song.ex b/lib/live_beats/media_library/song.ex index cf9cf50..e445212 100644 --- a/lib/live_beats/media_library/song.ex +++ b/lib/live_beats/media_library/song.ex @@ -24,7 +24,6 @@ defmodule LiveBeats.MediaLibrary.Song do field :position, :integer, default: 0 belongs_to :user, Accounts.User belongs_to :genre, LiveBeats.MediaLibrary.Genre - embeds_many :speech_segments, LiveBeats.MediaLibrary.TextSegment timestamps() end diff --git a/lib/live_beats/media_library/text_segment.ex b/lib/live_beats/media_library/text_segment.ex deleted file mode 100644 index 367ec15..0000000 --- a/lib/live_beats/media_library/text_segment.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule LiveBeats.MediaLibrary.TextSegment do - use Ecto.Schema - - embedded_schema do - field :start_time, :float - field :text, :string - field :in_progress?, :boolean, virtual: true, default: false - end -end diff --git a/lib/live_beats_web/live/profile_live.ex b/lib/live_beats_web/live/profile_live.ex index ee35bd2..c68434d 100644 --- a/lib/live_beats_web/live/profile_live.ex +++ b/lib/live_beats_web/live/profile_live.ex @@ -155,7 +155,6 @@ defmodule LiveBeatsWeb.ProfileLive do MediaLibrary.subscribe_to_profile(profile) Accounts.subscribe(current_user.id) Presence.subscribe(profile) - send(self(), :mounted) end active_song = MediaLibrary.get_current_active_song(profile) @@ -171,7 +170,6 @@ defmodule LiveBeatsWeb.ProfileLive do profile: profile, owns_profile?: MediaLibrary.owns_profile?(current_user, profile), songs_count: Enum.count(songs), - mounted?: false ) |> stream(:songs, songs) |> stream(:speech_segments, speech_segments, dom_id: &"ss-#{trunc(&1.start_time)}") @@ -229,8 +227,6 @@ defmodule LiveBeatsWeb.ProfileLive do end end - def handle_info(:mounted, socket), do: {:noreply, assign(socket, :mounted?, true) } - def handle_info({LiveBeatsWeb.Presence, %{user_joined: presence}}, socket) do {:noreply, assign_presence(socket, presence)} end @@ -284,17 +280,6 @@ defmodule LiveBeatsWeb.ProfileLive do end)} end - def handle_info( - {MediaLibrary, %MediaLibrary.Events.SpeechToText{song_id: id, segment: segment}}, - socket - ) do - if socket.assigns.active_song_id == id do - {:noreply, stream_insert(socket, :speech_segments, segment)} - else - {:noreply, socket} - end - end - def handle_info({MediaLibrary, %MediaLibrary.Events.SongDeleted{song: song}}, socket) do {:noreply, socket diff --git a/mix.exs b/mix.exs index 929d54e..b164b32 100644 --- a/mix.exs +++ b/mix.exs @@ -54,10 +54,7 @@ defmodule LiveBeats.MixProject do {:heroicons, "~> 0.2.2"}, {:castore, "~> 0.1.13"}, {:tailwind, "~> 0.1"}, - {:libcluster, "~> 3.3.1"}, - {:bumblebee, github: "elixir-nx/bumblebee"}, - {:exla, "~> 0.5.1"}, - {:erlexec, "~> 2.0"} + {:libcluster, "~> 3.3.1"} ] end diff --git a/priv/repo/migrations/20230308164408_add_speech_segments_to_songs.exs b/priv/repo/migrations/20230308164408_add_speech_segments_to_songs.exs deleted file mode 100644 index 503d726..0000000 --- a/priv/repo/migrations/20230308164408_add_speech_segments_to_songs.exs +++ /dev/null @@ -1,9 +0,0 @@ -defmodule LiveBeats.Repo.Migrations.AddSpeechSegmentsToSongs do - use Ecto.Migration - - def change do - alter table(:songs) do - add :speech_segments, {:array, :map}, null: false, default: [] - end - end -end