Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions apps/desktop-gpui/src/editor_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use cap_project::{
BackgroundBlurConfig, BackgroundBlurMode, CameraShape, CameraXPosition, CameraYPosition,
CaptionSegment, CaptionSettings, CornerStyle, CursorAnimationStyle, CursorRippleConfig,
KeyboardData, KeyboardSettings, ProjectConfiguration, RecordingMeta, ShadowConfiguration,
StereoMode,
StereoMode, transcription_ranges_cover, transcription_source_ranges,
};
use gpui::{
AnyElement, Bounds, Context, EntityId, FontWeight, Hsla, InteractiveElement, IntoElement,
Expand Down Expand Up @@ -3174,6 +3174,9 @@ impl EditorWindow {
};
let recording_durations = summary.clip_display_durations.clone();
let recording_duration = summary.recording_duration;
let timeline = self.project.timeline.clone();
Comment thread
yashranaway marked this conversation as resolved.
let transcribed_ranges =
transcription_source_ranges(timeline.as_ref(), &recording_durations);
let project_path = self.project_path.clone();
let model = self.selected_caption_model().name;
let language = self.sidebar.caption_language;
Expand All @@ -3185,9 +3188,16 @@ impl EditorWindow {

cx.spawn_in(window, async move |this, cx| {
let task_path = project_path.clone();
let task_durations = recording_durations.clone();
let task = gpui_tokio::Tokio::spawn(cx, async move {
tokio::task::spawn_blocking(move || {
transcription::transcribe_blocking(&task_path, model, language)
transcription::transcribe_blocking(
&task_path,
model,
language,
timeline.as_ref(),
&task_durations,
)
})
.await
.map_err(|error| format!("Transcription task panicked: {error}"))?
Expand All @@ -3197,18 +3207,35 @@ impl EditorWindow {
Err(error) => Err(format!("Transcription task failed: {error}")),
};

match result {
Ok(segments) => {
transcription::finish_generation(&project_path, None);
let _ = this.update_in(cx, |this, window, cx| {
let result = match result {
Ok(segments) => this
.update_in(cx, |this, window, cx| {
let current_ranges = transcription_source_ranges(
this.project.timeline.as_ref(),
&recording_durations,
);
if !transcription_ranges_cover(&transcribed_ranges, &current_ranges) {
return Err(
"The timeline changed during generation. Generate captions again."
.to_string(),
);
}
this.apply_generated_captions(
segments,
&recording_durations,
recording_duration,
window,
cx,
);
});
Ok(())
})
.unwrap_or(Ok(())),
Err(error) => Err(error),
};

match result {
Ok(()) => {
transcription::finish_generation(&project_path, None);
}
Err(error) => {
tracing::error!("caption generation failed: {error}");
Expand Down
Loading
Loading