RVC -> media_files

This commit is contained in:
Brandon Thomas committed 2023-10-20 05:14:00 -04:00
1 parent 2af57fcf3e
commit 471dcff697
1 file changed
+44 -26
@@ -3,6 +3,7 @@ use std::time::Instant;
use anyhow::anyhow;
use log::{error, info, warn};
use buckets::public::media_files::original_file::MediaFileBucketPath;
use buckets::public::media_uploads::original_file::MediaUploadOriginalFilePath;
use buckets::public::voice_conversion_results::original_file::VoiceConversionResultOriginalFilePath;
@@ -12,13 +13,14 @@ use container_common::filesystem::safe_delete_temp_file::safe_delete_temp_file;
use enums::by_table::generic_inference_jobs::inference_result_type::InferenceResultType;
use filesys::create_dir_all_if_missing::create_dir_all_if_missing;
use filesys::file_size::file_size;
use hashing::sha256::sha256_hash_file::sha256_hash_file;
use media::decode_basic_audio_info::decode_basic_audio_file_info;
use mimetypes::mimetype_for_file::get_mimetype_for_file;
use mysql_queries::payloads::generic_inference_args::generic_inference_args::PolymorphicInferenceArgs;
use mysql_queries::queries::generic_inference::job::list_available_generic_inference_jobs::AvailableInferenceJob;
use mysql_queries::queries::media_files::insert_media_file_from_voice_conversion::{insert_media_file_from_voice_conversion, InsertMediaFileArgs, VoiceConversionModelType};
use mysql_queries::queries::media_uploads::get_media_upload_for_inference::MediaUploadRecordForInference;
use mysql_queries::queries::voice_conversion::inference::get_voice_conversion_model_for_inference::VoiceConversionModelForInference;
use mysql_queries::queries::voice_conversion::results::insert_voice_conversion_result::{insert_voice_conversion_result, InsertArgs};
use tokens::tokens::media_uploads::MediaUploadToken;
use tokens::tokens::users::UserToken;
@@ -28,6 +30,9 @@ use crate::job::job_types::vc::rvc_v2::rvc_v2_inference_command::InferenceArgs;
use crate::job_dependencies::JobDependencies;
use crate::util::maybe_download_file_from_bucket::maybe_download_file_from_bucket;
const BUCKET_FILE_PREFIX : &str = "fakeyou_rvc_";
const BUCKET_FILE_EXTENSION : &str = ".wav";
pub struct RvcV2ProcessJobArgs<'a> {
pub job_dependencies: &'a JobDependencies,
pub job: &'a AvailableInferenceJob,
@@ -267,8 +272,6 @@ pub async fn process_job(args: RvcV2ProcessJobArgs<'_>) -> Result<JobSuccessResu
info!("Checking that output files exist...");
check_file_exists(&output_audio_fs_path).map_err(|e| ProcessSingleJobError::Other(e))?;
//check_file_exists(&output_metadata_fs_path).map_err(|e| ProcessSingleJobError::Other(e))?;
//check_file_exists(&output_spectrogram_fs_path).map_err(|e| ProcessSingleJobError::Other(e))?;
info!("Interrogating result file properties...");
@@ -286,11 +289,18 @@ pub async fn process_job(args: RvcV2ProcessJobArgs<'_>) -> Result<JobSuccessResu
warn!("Required a full decode of the output data to get duration! That's inefficient!");
}
info!("Calculating sha256...");
let file_checksum = sha256_hash_file(&output_audio_fs_path)
.map_err(|err| {
ProcessSingleJobError::Other(anyhow!("Error hashing file: {:?}", err))
})?;
// TODO: Make a new python image that generates spectrograms from any audio file.
let file_metadata = FileMetadata {
duration_millis: audio_info.duration_millis,
mimetype: maybe_mimetype,
mimetype: maybe_mimetype.clone(),
file_size_bytes,
};
@@ -301,7 +311,15 @@ pub async fn process_job(args: RvcV2ProcessJobArgs<'_>) -> Result<JobSuccessResu
job_progress_reporter.log_status("uploading result")
.map_err(|e| ProcessSingleJobError::Other(e))?;
let result_bucket_location = VoiceConversionResultOriginalFilePath::generate_new();
// let result_bucket_location = VoiceConversionResultOriginalFilePath::generate_new();
//
// let result_bucket_object_pathbuf = result_bucket_location.to_full_object_pathbuf();
//
// info!("Audio destination bucket path: {:?}", &result_bucket_object_pathbuf);
let result_bucket_location = MediaFileBucketPath::generate_new(
Some(BUCKET_FILE_PREFIX),
Some(BUCKET_FILE_EXTENSION));
let result_bucket_object_pathbuf = result_bucket_location.to_full_object_pathbuf();
@@ -318,24 +336,6 @@ pub async fn process_job(args: RvcV2ProcessJobArgs<'_>) -> Result<JobSuccessResu
safe_delete_temp_file(&output_audio_fs_path);
// // ==================== UPLOAD SPECTROGRAM TO BUCKETS ==================== //
//
// let spectrogram_result_object_path = args.job_dependencies.bucket_path_unifier.tts_inference_spectrogram_output_path(
// &job.uuid_idempotency_token); // TODO: Don't use this!
//
// info!("Spectrogram destination bucket path: {:?}", &spectrogram_result_object_path);
//
// info!("Uploading spectrogram...");
//
// args.job_dependencies.public_bucket_client.upload_filename_with_content_type(
// &spectrogram_result_object_path,
// &output_spectrogram_fs_path,
// "application/json")
// .await
// .map_err(|e| ProcessSingleJobError::Other(e))?;
//
// safe_delete_temp_file(&output_spectrogram_fs_path);
// ==================== DELETE DOWNLOADED FILE ==================== //
// NB: We should be using a tempdir, but to make absolutely certain we don't overflow the disk...
@@ -345,16 +345,34 @@ pub async fn process_job(args: RvcV2ProcessJobArgs<'_>) -> Result<JobSuccessResu
info!("Saving vc inference record...");
let (inference_result_token, id) = insert_voice_conversion_result(InsertArgs {
// let (inference_result_token, id) = insert_voice_conversion_result(InsertArgs {
// pool: &args.job_dependencies.mysql_pool,
// job: &job,
// public_bucket_hash: result_bucket_location.get_object_hash(),
// file_size_bytes: file_metadata.file_size_bytes,
// duration_millis: file_metadata.duration_millis.unwrap_or(0),
// is_on_prem: args.job_dependencies.container.is_on_prem,
// worker_hostname: &args.job_dependencies.container.hostname,
// worker_cluster: &args.job_dependencies.container.cluster_name,
// is_debug_worker: args.job_dependencies.worker_details.is_debug_worker
// })
// .await
// .map_err(|e| ProcessSingleJobError::Other(e))?;
let (inference_result_token, id) = insert_media_file_from_voice_conversion(InsertMediaFileArgs {
pool: &args.job_dependencies.mysql_pool,
job: &job,
public_bucket_hash: result_bucket_location.get_object_hash(),
voice_conversion_type: VoiceConversionModelType::SoVitsSvc,
maybe_mime_type: maybe_mimetype.as_deref(),
file_size_bytes: file_metadata.file_size_bytes,
duration_millis: file_metadata.duration_millis.unwrap_or(0),
sha256_checksum: &file_checksum,
public_bucket_directory_hash: result_bucket_location.get_object_hash(),
maybe_public_bucket_prefix: Some(BUCKET_FILE_PREFIX),
maybe_public_bucket_extension: Some(BUCKET_FILE_EXTENSION),
is_on_prem: args.job_dependencies.container.is_on_prem,
worker_hostname: &args.job_dependencies.container.hostname,
worker_cluster: &args.job_dependencies.container.cluster_name,
is_debug_worker: args.job_dependencies.worker_details.is_debug_worker
})
.await
.map_err(|e| ProcessSingleJobError::Other(e))?;