mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-06-16 04:10:33 +00:00
Reset
This commit is contained in:
parent
0832300e4b
commit
38d5158773
|
@ -10,19 +10,7 @@ defmodule LiveBeats.Application do
|
||||||
LiveBeats.MediaLibrary.attach()
|
LiveBeats.MediaLibrary.attach()
|
||||||
topologies = Application.get_env(:libcluster, :topologies) || []
|
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 = [
|
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]]},
|
{Cluster.Supervisor, [topologies, [name: LiveBeats.ClusterSupervisor]]},
|
||||||
{Task.Supervisor, name: LiveBeats.TaskSupervisor},
|
{Task.Supervisor, name: LiveBeats.TaskSupervisor},
|
||||||
# Start the Ecto repository
|
# Start the Ecto repository
|
||||||
|
|
|
@ -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
|
|
|
@ -22,8 +22,4 @@ defmodule LiveBeats.MediaLibrary.Events do
|
||||||
defmodule SongDeleted do
|
defmodule SongDeleted do
|
||||||
defstruct song: nil
|
defstruct song: nil
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule SpeechToText do
|
|
||||||
defstruct song_id: nil, segment: nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,6 @@ defmodule LiveBeats.MediaLibrary.Song do
|
||||||
field :position, :integer, default: 0
|
field :position, :integer, default: 0
|
||||||
belongs_to :user, Accounts.User
|
belongs_to :user, Accounts.User
|
||||||
belongs_to :genre, LiveBeats.MediaLibrary.Genre
|
belongs_to :genre, LiveBeats.MediaLibrary.Genre
|
||||||
embeds_many :speech_segments, LiveBeats.MediaLibrary.TextSegment
|
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
|
@ -155,7 +155,6 @@ defmodule LiveBeatsWeb.ProfileLive do
|
||||||
MediaLibrary.subscribe_to_profile(profile)
|
MediaLibrary.subscribe_to_profile(profile)
|
||||||
Accounts.subscribe(current_user.id)
|
Accounts.subscribe(current_user.id)
|
||||||
Presence.subscribe(profile)
|
Presence.subscribe(profile)
|
||||||
send(self(), :mounted)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
active_song = MediaLibrary.get_current_active_song(profile)
|
active_song = MediaLibrary.get_current_active_song(profile)
|
||||||
|
@ -171,7 +170,6 @@ defmodule LiveBeatsWeb.ProfileLive do
|
||||||
profile: profile,
|
profile: profile,
|
||||||
owns_profile?: MediaLibrary.owns_profile?(current_user, profile),
|
owns_profile?: MediaLibrary.owns_profile?(current_user, profile),
|
||||||
songs_count: Enum.count(songs),
|
songs_count: Enum.count(songs),
|
||||||
mounted?: false
|
|
||||||
)
|
)
|
||||||
|> stream(:songs, songs)
|
|> stream(:songs, songs)
|
||||||
|> stream(:speech_segments, speech_segments, dom_id: &"ss-#{trunc(&1.start_time)}")
|
|> stream(:speech_segments, speech_segments, dom_id: &"ss-#{trunc(&1.start_time)}")
|
||||||
|
@ -229,8 +227,6 @@ defmodule LiveBeatsWeb.ProfileLive do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_info(:mounted, socket), do: {:noreply, assign(socket, :mounted?, true) }
|
|
||||||
|
|
||||||
def handle_info({LiveBeatsWeb.Presence, %{user_joined: presence}}, socket) do
|
def handle_info({LiveBeatsWeb.Presence, %{user_joined: presence}}, socket) do
|
||||||
{:noreply, assign_presence(socket, presence)}
|
{:noreply, assign_presence(socket, presence)}
|
||||||
end
|
end
|
||||||
|
@ -284,17 +280,6 @@ defmodule LiveBeatsWeb.ProfileLive do
|
||||||
end)}
|
end)}
|
||||||
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
|
def handle_info({MediaLibrary, %MediaLibrary.Events.SongDeleted{song: song}}, socket) do
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|
|
5
mix.exs
5
mix.exs
|
@ -54,10 +54,7 @@ defmodule LiveBeats.MixProject do
|
||||||
{:heroicons, "~> 0.2.2"},
|
{:heroicons, "~> 0.2.2"},
|
||||||
{:castore, "~> 0.1.13"},
|
{:castore, "~> 0.1.13"},
|
||||||
{:tailwind, "~> 0.1"},
|
{:tailwind, "~> 0.1"},
|
||||||
{:libcluster, "~> 3.3.1"},
|
{:libcluster, "~> 3.3.1"}
|
||||||
{:bumblebee, github: "elixir-nx/bumblebee"},
|
|
||||||
{:exla, "~> 0.5.1"},
|
|
||||||
{:erlexec, "~> 2.0"}
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in a new issue