Skip to content

Commit

Permalink
new clie argument for friend uid
Browse files Browse the repository at this point in the history
  • Loading branch information
m13v committed Aug 3, 2024
1 parent 9d89d3e commit de9af00
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions screenpipe-server/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::task::JoinHandle;
use external_cloud_integrations::friend_wearable::send_data_to_friend_wearable;

pub enum RecorderControl {
Pause,
Resume,
Expand Down Expand Up @@ -49,12 +51,13 @@ pub async fn start_continuous_recording(
vision_control: Arc<AtomicBool>,
audio_devices_control: Arc<SegQueue<(AudioDevice, DeviceControl)>>,
save_text_files: bool,
cloud_audio: bool, // Added cloud_audio parameter
cloud_ocr: bool, // Added cloud_ocr parameter
cloud_audio: bool,
cloud_ocr: bool,
friend_wearable_uid: Option<String>, // Updated parameter
) -> Result<()> {
info!("Recording now");

let (whisper_sender, whisper_receiver) = create_whisper_channel(cloud_audio).await?; // Pass cloud_audio
let (whisper_sender, whisper_receiver) = create_whisper_channel(cloud_audio).await?;

let db_manager_video = Arc::clone(&db);
let db_manager_audio = Arc::clone(&db);
Expand All @@ -64,14 +67,17 @@ pub async fn start_continuous_recording(
let output_path_video = Arc::clone(&output_path);
let output_path_audio = Arc::clone(&output_path);

let friend_wearable_uid_video = friend_wearable_uid.clone(); // Clone for video handle

let video_handle = tokio::spawn(async move {
record_video(
db_manager_video,
output_path_video,
fps,
is_running_video,
save_text_files,
cloud_ocr, // Pass the cloud_ocr flag
cloud_ocr,
friend_wearable_uid_video, // Use the cloned version
)
.await
});
Expand All @@ -84,6 +90,7 @@ pub async fn start_continuous_recording(
whisper_sender,
whisper_receiver,
audio_devices_control,
friend_wearable_uid, // Use the original
)
.await
});
Expand All @@ -101,7 +108,8 @@ async fn record_video(
fps: f64,
is_running: Arc<AtomicBool>,
save_text_files: bool,
cloud_ocr: bool, // Added cloud_ocr parameter
cloud_ocr: bool,
friend_wearable_uid: Option<String>, // Updated parameter
) -> Result<()> {
debug!("record_video: Starting");
let db_chunk_callback = Arc::clone(&db);
Expand All @@ -122,7 +130,7 @@ async fn record_video(
fps,
new_chunk_callback,
save_text_files,
cloud_ocr, // Pass the cloud_ocr flag
cloud_ocr,
);

while is_running.load(Ordering::SeqCst) {
Expand Down Expand Up @@ -154,6 +162,20 @@ async fn record_video(
);
continue; // Skip to the next iteration
}

// Send data to friend wearable
if let Some(uid) = &friend_wearable_uid {
if let Err(e) = send_data_to_friend_wearable(
"screen".to_string(),
frame_id.to_string(),
frame.text.clone(),
uid, // Pass the UID to the function
) {
error!("Failed to send screen data to friend wearable: {}", e);
} else {
debug!("Sent screen data to friend wearable for frame {}", frame_id);
}
}
}
Err(e) => {
warn!("Failed to insert frame: {}", e);
Expand All @@ -176,6 +198,7 @@ async fn record_audio(
whisper_sender: UnboundedSender<AudioInput>,
mut whisper_receiver: UnboundedReceiver<TranscriptionResult>,
audio_devices_control: Arc<SegQueue<(AudioDevice, DeviceControl)>>,
friend_wearable_uid: Option<String>, // Updated parameter
) -> Result<()> {
let mut handles: HashMap<String, JoinHandle<()>> = HashMap::new();

Expand Down Expand Up @@ -287,15 +310,19 @@ async fn record_audio(
// Process whisper results
while let Ok(transcription) = whisper_receiver.try_recv() {
info!("Received transcription");
process_audio_result(&db, transcription).await;
process_audio_result(&db, transcription, friend_wearable_uid.as_deref()).await;
}

// Small delay to prevent busy-waiting
tokio::time::sleep(Duration::from_millis(100)).await;
}
}

async fn process_audio_result(db: &DatabaseManager, result: TranscriptionResult) {
async fn process_audio_result(
db: &DatabaseManager,
result: TranscriptionResult,
friend_wearable_uid: Option<&str>, // Updated parameter
) {
if result.error.is_some() || result.transcription.is_none() {
error!(
"Error in audio recording: {}. Not inserting audio result",
Expand Down Expand Up @@ -326,6 +353,20 @@ async fn process_audio_result(db: &DatabaseManager, result: TranscriptionResult)
"Inserted audio transcription for chunk {} from device {}",
audio_chunk_id, result.input.device
);

// Send data to friend wearable
if let Some(uid) = friend_wearable_uid {
if let Err(e) = send_data_to_friend_wearable(
"audio".to_string(),
audio_chunk_id.to_string(),
transcription.clone(),
uid, // Pass the UID to the function
) {
error!("Failed to send data to friend wearable: {}", e);
} else {
debug!("Sent audio data to friend wearable for chunk {}", audio_chunk_id);
}
}
}
}
Err(e) => error!(
Expand Down

0 comments on commit de9af00

Please sign in to comment.