diff --git a/src/App.jsx b/src/App.jsx index 721fed3..4629a2d 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -20,6 +20,7 @@ import { useVideoExport } from "./hooks/useVideoExport.js"; import { useVoiceRecorder } from "./hooks/useVoiceRecorder.js"; import { useVoiceGeneration } from "./hooks/useVoiceGeneration.js"; import { useAutoCaptions } from "./hooks/useAutoCaptions.js"; +import { useAutoEdit } from "./hooks/useAutoEdit.js"; import { useSourceAudioExtraction } from "./hooks/useSourceAudioExtraction.js"; import { useVocalSeparation } from "./hooks/useVocalSeparation.js"; import { useAvatarGeneration } from "./hooks/useAvatarGeneration.js"; @@ -76,6 +77,7 @@ export function App() { const [showExportMenu, setShowExportMenu] = useState(false); const [exportSettings, setExportSettings] = useState({ resolution: "1080", frameRate: 30, codec: "h264", quality: "high" }); const [captionVoiceFocusRequest, setCaptionVoiceFocusRequest] = useState(0); + const [selectedSourceAudioSegmentId, setSelectedSourceAudioSegmentId] = useState(""); const timelineImportRestoreRef = useRef(false); const [introClosing, setIntroClosing] = useState(false); const { @@ -349,6 +351,10 @@ export function App() { setScript, setSelectedSegmentId, setSelectedTrack, setVisionRecords, trackLocks, }); + const autoEdit = useAutoEdit({ + language: activeLanguage, visualSegments, commitCaptionSegments, setCaptionsEnabled, + setSelectedSegmentId, setSelectedTrack, notify, t, + }); const { clearAudioTrack, clearMusicTrack, clearSourceAudioTrack, commitAudio, replaceAudio, replaceMusic, replaceSourceAudio, @@ -475,7 +481,8 @@ export function App() { selectedSegmentIndex, selectedStickerSegmentId, selectedTrack, selectedVisualSegmentId, selectedVisualSegmentIndex, setAudioSegments, setCaptionSegments, setSelectedAudioSegmentId, setUserAssets, sourceAudioBlob, - sourceAudioName, stickerSegments, t, trackLocks, visualSegments, visualType, + sourceAudioLinked, sourceAudioName, selectedSourceAudioSegmentId, + setSelectedSourceAudioSegmentId, stickerSegments, t, trackLocks, visualSegments, visualType, }); useEditorLifecycle({ @@ -840,6 +847,7 @@ export function App() { automaticCaptionProgress={status === "captioning" ? progress : 0} avatarPanelOpen={avatarPanelOpen} smartMode={smartMode} + autoEdit={autoEdit} uiLanguage={activeLanguage} visionAnalysis={previewVisionAnalysis} visionOptions={previewVisionOptions} @@ -949,6 +957,8 @@ export function App() { sourceAudioClipPercent={sourceAudioClipPercent} sourceAudioStartPercent={sourceAudioStartPercent} sourceAudioDuration={sourceAudioDuration} + selectedSourceAudioSegmentId={selectedSourceAudioSegmentId} + setSelectedSourceAudioSegmentId={setSelectedSourceAudioSegmentId} audioBlob={audioBlob} peaks={peaks} audioClipPercent={audioClipPercent} diff --git a/src/components/Timeline.jsx b/src/components/Timeline.jsx index 7cf99fb..7250c6a 100644 --- a/src/components/Timeline.jsx +++ b/src/components/Timeline.jsx @@ -118,6 +118,7 @@ function getImageTimelineThumbnailCount({ duration, timelineDuration, contentWid export function Timeline({ t, + trOption, undo, redo, handleDeleteTrack, @@ -190,6 +191,8 @@ export function Timeline({ sourceAudioClipPercent, sourceAudioStartPercent, sourceAudioDuration, + selectedSourceAudioSegmentId, + setSelectedSourceAudioSegmentId, audioBlob, peaks, audioClipPercent, @@ -207,6 +210,16 @@ export function Timeline({ startMusicMove, }) { const [transitionEditor, setTransitionEditor] = useState(null); + const [musicClipSelected, setMusicClipSelected] = useState(false); + + const clearClipSelections = (except = "") => { + if (except !== "visual") setSelectedVisualSegmentId(""); + if (except !== "sticker") setSelectedStickerSegmentId(""); + if (except !== "caption") setSelectedSegmentId(""); + if (except !== "voice") setSelectedAudioSegmentId(""); + if (except !== "source") setSelectedSourceAudioSegmentId(""); + if (except !== "music") setMusicClipSelected(false); + }; const updateJunctionTransition = (index, patch) => { setVisualSegments((items) => items.map((item, itemIndex) => itemIndex === index @@ -260,10 +273,14 @@ export function Timeline({ }; const selectContextTarget = (track, segmentId = "") => { openTrackPanel(track); + const selectionType = { image: "visual", sticker: "sticker", caption: "caption", audio: "voice", source: "source", music: "music" }[track]; + clearClipSelections(selectionType); if (track === "image" && segmentId) setSelectedVisualSegmentId(segmentId); if (track === "sticker" && segmentId) setSelectedStickerSegmentId(segmentId); if (track === "caption" && segmentId) setSelectedSegmentId(segmentId); if (track === "audio" && segmentId) setSelectedAudioSegmentId(segmentId); + if (track === "source" && segmentId) setSelectedSourceAudioSegmentId(segmentId); + if (track === "music" && segmentId) setMusicClipSelected(true); }; const showTrackContextMenu = (event, track, segmentId = "") => { event.preventDefault(); event.stopPropagation(); @@ -626,6 +643,7 @@ export function Timeline({ } setSelectedTrack("sticker"); setActiveTool("stickers"); + clearClipSelections("sticker"); setSelectedStickerSegmentId(segment.id); seekTo(segment.start || 0); }} @@ -882,12 +900,14 @@ export function Timeline({ return; } setSelectedTrack("image"); + clearClipSelections("visual"); setSelectedVisualSegmentId(segment.id); }} onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); setSelectedTrack("image"); + clearClipSelections("visual"); setSelectedVisualSegmentId(segment.id); } }} @@ -953,7 +973,7 @@ export function Timeline({ className={`visual-junction ${transition.id !== "none" ? "has-transition" : ""}`} key={`junction-${segment.id}`} type="button" - aria-label={`转场:${TRANSITIONS.find((item) => item.id === transition.id)?.name || "无转场"}`} + aria-label={`${t("transition")}: ${trOption(TRANSITIONS.find((item) => item.id === transition.id)?.name || "无转场")}`} title="设置转场" style={{ left: `${((range?.end || 0) / Math.max(0.01, timelineDuration)) * 100}%` }} onPointerDown={(event) => event.stopPropagation()} @@ -1028,6 +1048,7 @@ export function Timeline({ } setSelectedTrack("caption"); setActiveTool("caption"); + clearClipSelections("caption"); setSelectedSegmentId(segment.id); seekTo(segmentRange?.start ?? getSegmentStartTime(displayedCaptionSegments, index, captionTargetDuration)); }} @@ -1055,7 +1076,10 @@ export function Timeline({ assetDropTargetTrack === "source" ? "is-drop-target" : "" } ${assetDropPulseTrack === "source" ? "is-drop-landing" : ""}`} type="button" - onClick={() => setSelectedTrack("source")} + onClick={() => { + setSelectedTrack("source"); + setSelectedSourceAudioSegmentId(""); + }} onDragOver={(event) => handleTrackAssetDragOver(event, "source")} onDragLeave={(event) => handleTrackAssetDragLeave(event, "source")} onDrop={(event) => handleTrackAssetDrop(event, "source")} @@ -1068,7 +1092,7 @@ export function Timeline({ {renderAssetDropSlot("source")} {sourceAudioBlob && sourceAudioLinked && linkedSourceAudioSegments.length ? linkedSourceAudioSegments.map((segment) => (
0 ? Math.max(0.01, Math.min(100, (segment.duration / timelineDuration) * 100)) : 0}%`, @@ -1076,19 +1100,31 @@ export function Timeline({ }} onContextMenu={(event) => showTrackContextMenu(event, "source", segment.id)} onPointerDown={startSourceAudioMove} + onClick={(event) => { + event.stopPropagation(); + setSelectedTrack("source"); + clearClipSelections("source"); + setSelectedSourceAudioSegmentId(segment.id); + }} > {formatTime(segment.duration)}
)) : sourceAudioBlob ? (
showTrackContextMenu(event, "source", "source-audio")} onPointerDown={startSourceAudioMove} + onClick={(event) => { + event.stopPropagation(); + setSelectedTrack("source"); + clearClipSelections("source"); + setSelectedSourceAudioSegmentId("source-audio"); + }} > {formatTime(sourceAudioDuration)} @@ -1128,6 +1164,7 @@ export function Timeline({ onClick={(event) => { event.stopPropagation(); setSelectedTrack("audio"); + clearClipSelections("voice"); setSelectedAudioSegmentId(segment.id); seekTo(segment.start); }} @@ -1146,7 +1183,10 @@ export function Timeline({ assetDropTargetTrack === "music" ? "is-drop-target" : "" } ${assetDropPulseTrack === "music" ? "is-drop-landing" : ""}`} type="button" - onClick={() => setSelectedTrack("music")} + onClick={() => { + setSelectedTrack("music"); + setMusicClipSelected(false); + }} onDragOver={(event) => handleTrackAssetDragOver(event, "music")} onDragLeave={(event) => handleTrackAssetDragLeave(event, "music")} onDrop={(event) => handleTrackAssetDrop(event, "music")} @@ -1158,7 +1198,7 @@ export function Timeline({ ) : null} {renderAssetDropSlot("music")} {musicBlob ? ( -
showTrackContextMenu(event, "music", "music-audio")}> +
showTrackContextMenu(event, "music", "music-audio")} onClick={(event) => { event.stopPropagation(); setSelectedTrack("music"); clearClipSelections("music"); setMusicClipSelected(true); }}> {formatTime(musicDuration)}
@@ -1222,17 +1262,17 @@ export function Timeline({ const transition = segment?.transition || { id: "none", duration: 0.5 }; const maxDuration = Math.max(0.1, Math.min(2, (segment?.duration || 0.5) / 2, (displayedVisualSegments[transitionEditor.index + 1]?.duration || 0.5) / 2)); return ( -
event.stopPropagation()}> -
转场
+
event.stopPropagation()}> +
{t("transition")}
{TRANSITIONS.map((option) => ( ))}
diff --git a/src/components/VoicePanel.jsx b/src/components/VoicePanel.jsx index 0e2d470..21e97fe 100644 --- a/src/components/VoicePanel.jsx +++ b/src/components/VoicePanel.jsx @@ -19,6 +19,26 @@ import { getCaptionVoiceSegment } from "../lib/captionVoice.js"; import { normalizeVisualKeyframes } from "../lib/visualEffects.js"; import { HistoryPanel, MyVoicesPanel, SmartVisionPanel, VisualEffectsPanel, VoiceSynthesisPanel } from "./panels.jsx"; +function AutoEditPanel({ t, hasVisual, language, autoEdit }) { + const availability = autoEdit?.support?.availability || "unknown"; + const languageFallback = autoEdit?.support?.language && autoEdit.support.language !== language; + const ready = availability === "available" || availability === "downloadable" || availability === "downloading"; + return ( +
+
{t("autoEditCreateTitle")}{t("autoEditCreateDesc")}
+
+
{t("autoEditBrowserModel")}{t(`autoEditStatus_${availability}`)}
+

{t("autoEditPrivacyHint")}

+ {languageFallback ?

{t("autoEditLanguageFallback")}

: null} + +
+
1

{t("autoEditStepScenes")}{t("autoEditStepScenesHint")}

2

{t("autoEditStepCaptions")}{t("autoEditStepCaptionsHint")}

3

{t("autoEditStepTimeline")}{t("autoEditStepTimelineHint")}

+ {autoEdit?.job?.running ?
{autoEdit.job.phase}{autoEdit.job.progress}%
: null} + +
+ ); +} + function CaptionContextPanel({ t, captionSegments, @@ -339,6 +359,7 @@ export function VoicePanel({ automaticCaptionProgress, avatarPanelOpen, smartMode = "auto-edit", + autoEdit, uiLanguage, visionAnalysis, visionOptions, @@ -383,7 +404,7 @@ export function VoicePanel({ const isStickerContext = selectedTrack === "sticker" && Boolean(selectedStickerSegment); const selectedCaptionAudioSegment = getCaptionVoiceSegment(audioSegments, selectedCaptionSegment); const title = isSmartAutoContext ? t("smartAutoEdit") : isSmartFrameContext ? t("smartFrame") : isAvatarContext ? t("avatarTitle") : isStickerContext ? t("stickerProperties") : isVisualContext ? t("visualPanelTitle") : isCaptionContext ? t("caption") : isAudioClipContext ? t("audioClipProperties") : t("aiVoice"); - const panelStatusText = isSmartAutoContext ? t("smartComingSoon") : isSmartFrameContext ? (hasVisual ? t("smartVisualReady") : t("smartWaitingVisual")) : isCaptionContext + const panelStatusText = isSmartAutoContext ? t(`autoEditStatus_${autoEdit?.support?.availability || "unknown"}`) : isSmartFrameContext ? (hasVisual ? t("smartVisualReady") : t("smartWaitingVisual")) : isCaptionContext ? captionSegments.length ? `${captionSegments.length} ${t("captionSegmentsUnit", "条字幕")}` : t("noCaptionSegments") @@ -412,6 +433,10 @@ export function VoicePanel({ return () => cancelAnimationFrame(frame); }, [captionVoiceFocusRequest, isCaptionContext]); + useEffect(() => { + panelRef.current?.querySelector(".voice-tab-body")?.scrollTo({ top: 0 }); + }, [activeTool, smartMode]); + return (