mirror of
https://github.com/fly-apps/live_beats.git
synced 2025-01-05 05:08:39 +00:00
WIP
This commit is contained in:
parent
6c13ad3b9b
commit
0c8a1ccac0
4 changed files with 32 additions and 32 deletions
|
@ -209,17 +209,7 @@ defmodule LiveBeats.MediaLibrary do
|
|||
|> Enum.filter(&match?({{:song, _ref}, _}, &1))
|
||||
|> Enum.map(fn {{:song, ref}, song} ->
|
||||
consume_file.(ref, fn tmp_path -> store_mp3(song, tmp_path) end)
|
||||
|
||||
Task.Supervisor.start_child(LiveBeats.TaskSupervisor, fn ->
|
||||
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})
|
||||
segment
|
||||
end)
|
||||
|
||||
insert_speech_segments(song, segments)
|
||||
end)
|
||||
async_text_to_speech(song, user)
|
||||
|
||||
{ref, song}
|
||||
end)
|
||||
|
@ -240,8 +230,17 @@ defmodule LiveBeats.MediaLibrary do
|
|||
end
|
||||
end
|
||||
|
||||
defp insert_speech_segments(song, segments) do
|
||||
Repo.update_all(from(s in Song, where: s.id == ^song.id), set: [speech_segments: segments])
|
||||
defp async_text_to_speech(%Song{} = song, %Accounts.User{} = user) do
|
||||
Task.Supervisor.start_child(LiveBeats.TaskSupervisor, fn ->
|
||||
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})
|
||||
segment
|
||||
end)
|
||||
|
||||
Repo.update_all(from(s in Song, where: s.id == ^song.id), set: [speech_segments: segments])
|
||||
end)
|
||||
end
|
||||
|
||||
defp broadcast_imported(%Accounts.User{} = user, songs) do
|
||||
|
|
|
@ -51,9 +51,19 @@ defmodule LiveBeats.MediaLibrary.Song do
|
|||
def put_stats(%Ecto.Changeset{} = changeset, %LiveBeats.MP3Stat{} = stat) do
|
||||
changeset
|
||||
|> put_duration(stat.duration)
|
||||
|> maybe_put(:artist, stat.artist)
|
||||
|> maybe_put(:attribution, stat.attrib)
|
||||
|> Ecto.Changeset.put_change(:mp3_filesize, stat.size)
|
||||
end
|
||||
|
||||
def maybe_put(%Ecto.Changeset{} = changeset, field, value) do
|
||||
if Ecto.Changeset.get_field(changeset, field) in [nil, ""] do
|
||||
Ecto.Changeset.change(changeset, %{field => value})
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end
|
||||
|
||||
defp put_duration(%Ecto.Changeset{} = changeset, duration) when is_integer(duration) do
|
||||
changeset
|
||||
|> Ecto.Changeset.change(%{duration: duration})
|
||||
|
|
|
@ -8,7 +8,7 @@ defmodule LiveBeats.MP3Stat do
|
|||
import Bitwise
|
||||
alias LiveBeats.MP3Stat
|
||||
|
||||
defstruct duration: 0, size: 0, path: nil, title: nil, artist: nil, tags: nil
|
||||
defstruct duration: 0, size: 0, path: nil, title: nil, artist: nil, tags: nil, attrib: nil
|
||||
|
||||
@declared_frame_ids ~w(AENC APIC ASPI COMM COMR ENCR EQU2 ETCO GEOB GRID LINK MCDI MLLT OWNE PRIV PCNT POPM POSS RBUF RVA2 RVRB SEEK SIGN SYLT SYTC TALB TBPM TCOM TCON TCOP TDEN TDLY TDOR TDRC TDRL TDTG TENC TEXT TFLT TIPL TIT1 TIT2 TIT3 TKEY TLAN TLEN TMCL TMED TMOO TOAL TOFN TOLY TOPE TOWN TPE1 TPE2 TPE3 TPE4 TPOS TPRO TPUB TRCK TRSN TRSO TSOA TSOP TSOT TSRC TSSE TSST TXXX UFID USER USLT WCOM WCOP WOAF WOAR WOAS WORS WPAY WPUB WXXX)
|
||||
|
||||
|
@ -42,6 +42,13 @@ defmodule LiveBeats.MP3Stat do
|
|||
duration when is_float(duration) and duration > 0 ->
|
||||
title = Enum.at(tag_info["TIT2"] || [], 0)
|
||||
artist = Enum.at(tag_info["TPE1"] || [], 0)
|
||||
|
||||
attrib =
|
||||
case tag_info["COMM"] do
|
||||
{_, _, info} -> info
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
seconds = round(duration)
|
||||
|
||||
{:ok,
|
||||
|
@ -51,7 +58,8 @@ defmodule LiveBeats.MP3Stat do
|
|||
path: path,
|
||||
tags: tag_info,
|
||||
title: title,
|
||||
artist: artist
|
||||
artist: artist,
|
||||
attrib: attrib
|
||||
}}
|
||||
|
||||
_other ->
|
||||
|
|
|
@ -54,19 +54,6 @@ defmodule LiveBeatsWeb.ProfileLive do
|
|||
</:actions>
|
||||
</.title_bar>
|
||||
|
||||
<div
|
||||
id={"text-to-speech-#{@active_song_id}"}
|
||||
phx-update="stream"
|
||||
class="p-6 max-h-[200px] overflow-y-scroll"
|
||||
>
|
||||
<div :for={{id, segment} <- @streams.speech_segments} id={id}>
|
||||
<span class="min-w-[40px] inline-block text-gray-400">
|
||||
[<%= seconds_to_mm_ss(segment.start_time) %>]
|
||||
</span>
|
||||
<%= segment.text %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Presence.listening_now
|
||||
presences={@presences}
|
||||
presence_ids={@presence_ids}
|
||||
|
@ -434,8 +421,4 @@ defmodule LiveBeatsWeb.ProfileLive do
|
|||
uri = URI.parse(url_str)
|
||||
uri.host <> uri.path
|
||||
end
|
||||
|
||||
defp seconds_to_mm_ss(seconds) do
|
||||
seconds |> trunc() |> Time.from_seconds_after_midnight() |> Calendar.strftime("%M:%S")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue