Python
added mp3 audio output
DeepBeepMeepd8f47a5c8fe3
diff --git a/README.md b/README.mdindex a814778..a303c75 100644--- a/README.md+++ b/README.md@@ -26,7 +26,7 @@ WanGP supports the Wan (and derived models), Hunyuan Video, Flux, Qwen, Z-Image,## 🔥 Latest Updates :-### January 25th 2026: WanGP v10.51, Music for your Hearts+### January 26th 2026: WanGP v10.53, Music for your HeartsWanGP Special *TTS* (Text To Speech) Release:@@ -40,8 +40,14 @@ WanGP Special *TTS* (Text To Speech) Release:- **Custom Output folder for Audio Gens**: you can now choose a different folder for the *Audio Outputs*- **Default Memory Profile for Audio Models**: TTS models can get very slow if you use profile 4 (being autoregressive models, they will need to load all the layers one per one to generate one single audio token then rinse & repeat). On the other hand, they dont't need as much VRAM, so you can now define a more agressive profile (3+ for instance)+- **Various Improvements**:+ - Video /Audio Galleries now support deletions of gens done outside WanGP+ - added *MP3 support* for audio outputs+ - *Check for Updates* button for *Plugins* to see in a glance if any of your plugin can be updated+*update 10.51*: new Heart Mula Finetune better at following instructions, Extra settings (cfg, top k) for TTS models, Rife v4\-*update 10.52*: updated plugin list and added version tracking+*update 10.52*: updated plugin list and added version tracking\+*update 10.53*: video/audio gallery now support deletions### January 20th 2026: WanGP v10.43, The Cost Saver*GPUs are expensive, RAM is expensive, SSD are expensive, sadly we live now in a GPU & RAM poor.*diff --git a/plugins/wan2gp-configuration/plugin.py b/plugins/wan2gp-configuration/plugin.pyindex 7d53327..ba68fa1 100644--- a/plugins/wan2gp-configuration/plugin.py+++ b/plugins/wan2gp-configuration/plugin.py@@ -214,7 +214,21 @@ class ConfigTabPlugin(WAN2GPPlugin):with gr.Tab("Outputs"):self.video_output_codec_choice = gr.Dropdown(choices=[("x265 CRF 28 (Balanced)", 'libx265_28'), ("x264 Level 8 (Balanced)", 'libx264_8'), ("x265 CRF 8 (High Quality)", 'libx265_8'), ("x264 Level 10 (High Quality)", 'libx264_10'), ("x264 Lossless", 'libx264_lossless')], value=self.server_config.get("video_output_codec", "libx264_8"), label="Video Codec")self.image_output_codec_choice = gr.Dropdown(choices=[("JPEG Q85", 'jpeg_85'), ("WEBP Q85", 'webp_85'), ("JPEG Q95", 'jpeg_95'), ("WEBP Q95", 'webp_95'), ("WEBP Lossless", 'webp_lossless'), ("PNG Lossless", 'png')], value=self.server_config.get("image_output_codec", "jpeg_95"), label="Image Codec")- self.audio_output_codec_choice = gr.Dropdown(choices=[("AAC 128 kbit", 'aac_128')], value=self.server_config.get("audio_output_codec", "aac_128"), visible=False, label="Audio Codec to use")+ self.audio_output_codec_choice = gr.Dropdown(choices=[("AAC 128 kbit", 'aac_128')], value=self.server_config.get("audio_output_codec", "aac_128"), visible=True, label="Audio Codec to use for mp4 container")+ audio_standalone_default = self.server_config.get("audio_stand_alone_output_codec", "wav")+ if audio_standalone_default == "mp3":+ audio_standalone_default = "mp3_192"+ self.audio_stand_alone_output_codec_choice = gr.Dropdown(+ choices=[+ ("WAV (Lossless)", "wav"),+ ("MP3 128 kbps", "mp3_128"),+ ("MP3 192 kbps", "mp3_192"),+ ("MP3 320 kbps", "mp3_320"),+ ],+ value=audio_standalone_default,+ visible=True,+ label="Audio Codec to use for standalone audio files",+ )self.metadata_choice = gr.Dropdown(choices=[("Export JSON files", "json"), ("Embed metadata in file (Exif/tag)", "metadata"), ("None", "none")],value=self.server_config.get("metadata_type", "metadata"), label="Metadata Handling"@@ -248,7 +262,7 @@ class ConfigTabPlugin(WAN2GPPlugin):self.video_profile_choice, self.image_profile_choice, self.audio_profile_choice,self.preload_in_VRAM_choice, self.max_reserved_loras_choice,self.enhancer_enabled_choice, self.enhancer_mode_choice, self.mmaudio_mode_choice, self.mmaudio_persistence_choice, self.rife_version_choice,- self.video_output_codec_choice, self.image_output_codec_choice, self.audio_output_codec_choice,+ self.video_output_codec_choice, self.image_output_codec_choice, self.audio_output_codec_choice, self.audio_stand_alone_output_codec_choice,self.metadata_choice, self.embed_source_images_choice,self.video_save_path_choice, self.image_save_path_choice, self.audio_save_path_choice,self.notification_sound_enabled_choice, self.notification_sound_volume_choice,@@ -298,7 +312,7 @@ class ConfigTabPlugin(WAN2GPPlugin):video_profile_choice, image_profile_choice, audio_profile_choice,preload_in_VRAM_choice, max_reserved_loras_choice,enhancer_enabled_choice, enhancer_mode_choice, mmaudio_mode_choice, mmaudio_persistence_choice, rife_version_choice,- video_output_codec_choice, image_output_codec_choice, audio_output_codec_choice,+ video_output_codec_choice, image_output_codec_choice, audio_output_codec_choice, audio_stand_alone_output_codec_choice,metadata_choice, embed_source_images_choice,save_path_choice, image_save_path_choice, audio_save_path_choice,notification_sound_enabled_choice, notification_sound_volume_choice,@@ -337,6 +351,7 @@ class ConfigTabPlugin(WAN2GPPlugin):"max_reserved_loras": max_reserved_loras_choice,"video_output_codec": video_output_codec_choice, "image_output_codec": image_output_codec_choice,"audio_output_codec": audio_output_codec_choice,+ "audio_stand_alone_output_codec": audio_stand_alone_output_codec_choice,"model_hierarchy_type": model_hierarchy_type_choice,"checkpoints_paths": checkpoints_paths,"queue_color_scheme": queue_color_scheme_choice,@@ -367,7 +382,7 @@ class ConfigTabPlugin(WAN2GPPlugin):"notification_sound_enabled", "notification_sound_volume", "mmaudio_mode","mmaudio_persistence", "mmaudio_enabled", "rife_version","max_frames_multiplier", "display_stats", "enable_4k_resolutions", "max_reserved_loras", "video_output_codec", "video_container",- "embed_source_images", "image_output_codec", "audio_output_codec", "checkpoints_paths",+ "embed_source_images", "image_output_codec", "audio_output_codec", "audio_stand_alone_output_codec", "checkpoints_paths","model_hierarchy_type", "UI_theme", "queue_color_scheme"]diff --git a/shared/utils/audio_metadata.py b/shared/utils/audio_metadata.pyindex e3560e6..300818f 100644--- a/shared/utils/audio_metadata.py+++ b/shared/utils/audio_metadata.py@@ -1,6 +1,7 @@import structfrom typing import Optionalimport json+import osdef write_wav_text_chunk(in_path: str, out_path: str, text: str,fourcc: bytes = b'json', encoding: str = 'utf-8') -> None:@@ -96,8 +97,61 @@ def read_wav_text_chunk(path: str, fourcc: bytes = b'json', encoding: str = 'utfreturn None+def _write_mp3_text_tag(path: str, text: str, tag_key: str = "WanGP") -> None:+ try:+ from mutagen.id3 import ID3, ID3NoHeaderError, TXXX+ except Exception as exc:+ raise RuntimeError("mutagen is required for mp3 metadata") from exc+ try:+ tag = ID3(path)+ except ID3NoHeaderError:+ tag = ID3()+ for key in list(tag.keys()):+ frame = tag.get(key)+ if isinstance(frame, TXXX) and frame.desc == tag_key:+ del tag[key]+ tag.add(TXXX(encoding=3, desc=tag_key, text=[text]))+ tag.save(path)+++def _read_mp3_text_tag(path: str, tag_key: str = "WanGP") -> Optional[str]:+ try:+ from mutagen.id3 import ID3, ID3NoHeaderError, TXXX, COMM+ except Exception:+ return None+ try:+ tag = ID3(path)+ except ID3NoHeaderError:+ return None+ for frame in tag.getall("TXXX"):+ if isinstance(frame, TXXX) and frame.desc == tag_key:+ if frame.text:+ return frame.text[0]+ for frame in tag.getall("COMM"):+ if isinstance(frame, COMM) and frame.desc == tag_key:+ return frame.text[0] if frame.text else None+ return None++def save_audio_metadata(path, configs):- write_wav_text_chunk(path, path, json.dumps(configs))+ ext = os.path.splitext(path)[1].lower()+ payload = json.dumps(configs)+ if ext == ".mp3":+ _write_mp3_text_tag(path, payload)+ elif ext == ".wav":+ write_wav_text_chunk(path, path, payload)+ else:+ raise ValueError(f"Unsupported audio metadata format: {ext}")+def read_audio_metadata(path):- return json.loads(read_wav_text_chunk(path))\ No newline at end of file+ ext = os.path.splitext(path)[1].lower()+ if ext == ".mp3":+ raw = _read_mp3_text_tag(path)+ elif ext == ".wav":+ raw = read_wav_text_chunk(path)+ else:+ return None+ if not raw:+ return None+ return json.loads(raw)diff --git a/shared/utils/audio_video.py b/shared/utils/audio_video.pyindex 91ad417..2e544ee 100644--- a/shared/utils/audio_video.py+++ b/shared/utils/audio_video.py@@ -12,6 +12,8 @@ import torchfrom PIL import Imageimport os.path as ospimport json+import numpy as np+import soundfile as sfdef rand_name(length=8, suffix=''):name = binascii.b2a_hex(os.urandom(length)).decode('utf-8')@@ -22,6 +24,99 @@ def rand_name(length=8, suffix=''):return name+def _prepare_audio_array(audio_data):+ if torch.is_tensor(audio_data):+ audio_data = audio_data.detach().cpu().float().numpy()+ else:+ audio_data = np.asarray(audio_data, dtype=np.float32)+ if audio_data.ndim == 2 and audio_data.shape[0] <= 8 and audio_data.shape[1] > audio_data.shape[0]:+ audio_data = audio_data.T+ return audio_data+++def write_wav_file(path, audio_data, sample_rate):+ audio_array = _prepare_audio_array(audio_data)+ sf.write(path, audio_array, int(sample_rate))+ return path+++def _get_audio_codec_settings(codec_key):+ if not codec_key:+ codec_key = "wav"+ codec_key = str(codec_key).lower()+ if codec_key == "mp3":+ codec_key = "mp3_192"+ settings = {+ "wav": {"ext": "wav", "format": "wav"},+ "mp3_128": {"ext": "mp3", "format": "mp3", "bitrate": "128k"},+ "mp3_192": {"ext": "mp3", "format": "mp3", "bitrate": "192k"},+ "mp3_320": {"ext": "mp3", "format": "mp3", "bitrate": "320k"},+ }+ return settings.get(codec_key, settings["wav"])+++def get_audio_codec_extension(codec_key):+ return _get_audio_codec_settings(codec_key)["ext"]+++def _run_ffmpeg_encode(input_path, output_path, codec, bitrate=None, sample_rate=None, drop_video=False):+ cmd = ["ffmpeg", "-y", "-v", "error", "-i", input_path]+ if drop_video:+ cmd.append("-vn")+ cmd += ["-c:a", codec]+ if bitrate:+ cmd += ["-b:a", bitrate]+ if sample_rate:+ cmd += ["-ar", str(int(sample_rate))]+ cmd.append(output_path)+ subprocess.run(cmd, check=True, capture_output=True, text=True)+++def save_audio_file(path, audio_data, sample_rate, codec_key="wav"):+ settings = _get_audio_codec_settings(codec_key)+ ext = settings["ext"]+ if not path.lower().endswith(f".{ext}"):+ path = osp.splitext(path)[0] + f".{ext}"+ if settings["format"] == "wav":+ return write_wav_file(path, audio_data, sample_rate)+ fd, tmp_path = tempfile.mkstemp(suffix=".wav", prefix="audio_")+ os.close(fd)+ try:+ write_wav_file(tmp_path, audio_data, sample_rate)+ _run_ffmpeg_encode(tmp_path, path, "libmp3lame", bitrate=settings.get("bitrate"), sample_rate=sample_rate)+ finally:+ try:+ os.remove(tmp_path)+ except OSError:+ pass+ return path+++def extract_audio_track_to_wav(video_path, output_dir, suffix=""):+ if not video_path:+ return None+ try:+ video_path = os.fspath(video_path)+ except TypeError:+ return None+ try:+ import ffmpeg+ except Exception:+ return None+ output_dir = output_dir or os.path.dirname(video_path) or "."+ output_path = get_available_filename(output_dir, video_path, suffix=suffix, force_extension=".wav")+ try:+ (+ ffmpeg.input(video_path)+ .output(output_path, **{"map": "0:a:0", "acodec": "pcm_s16le"})+ .overwrite_output()+ .run(quiet=True)+ )+ except Exception:+ return None+ return output_path++def extract_audio_tracks(source_video, verbose=False, query_only=False):"""@@ -464,3 +559,4 @@ def read_image_metadata(image_path):return Noneexcept Exception as e:print(f"Error reading metadata: {e}"); return None+diff --git a/wgp.py b/wgp.pyindex c567a7f..d775d9f 100644--- a/wgp.py+++ b/wgp.py@@ -37,7 +37,7 @@ from shared.utils.utils import convert_tensor_to_image, save_image, get_video_infrom shared.utils.utils import calculate_new_dimensions, get_outpainting_frame_location, get_outpainting_full_area_dimensionsfrom shared.utils.utils import has_video_file_extension, has_image_file_extension, has_audio_file_extensionfrom shared.utils.audio_video import extract_audio_tracks, combine_video_with_audio_tracks, combine_and_concatenate_video_with_audio_tracks, cleanup_temp_audio_files, save_video, save_image-from shared.utils.audio_video import save_image_metadata, read_image_metadata, extract_audio_track_to_wav, write_wav_file+from shared.utils.audio_video import save_image_metadata, read_image_metadata, extract_audio_track_to_wav, write_wav_file, save_audio_file, get_audio_codec_extensionfrom shared.utils.audio_metadata import save_audio_metadata, read_audio_metadatafrom shared.utils.video_metadata import save_video_metadatafrom shared.match_archi import match_nvidia_architecture@@ -85,7 +85,7 @@ AUTOSAVE_TEMPLATE_PATH = AUTOSAVE_FILENAMECONFIG_FILENAME = "wgp_config.json"PROMPT_VARS_MAX = 10target_mmgp_version = "3.7.2"-WanGP_version = "10.52"+WanGP_version = "10.53"settings_version = 2.44max_source_video_frames = 3000prompt_enhancer_image_caption_model, prompt_enhancer_image_caption_processor, prompt_enhancer_llm_model, prompt_enhancer_llm_tokenizer = None, None, None, None@@ -3942,7 +3942,7 @@ def select_video(state, current_gallery_tab, input_file_list, file_selected, audgen = get_gen_info(state)if source=="video":if current_gallery_tab != 0:- return [gr.update()] * 7+ return [gr.update()] * 9file_list, file_settings_list = get_file_list(state, input_file_list)data= event_data._dataif data!=None and isinstance(data, dict):@@ -3956,7 +3956,7 @@ def select_video(state, current_gallery_tab, input_file_list, file_selected, audfiles, settings_list = file_list, file_settings_listelse:if current_gallery_tab != 1:- return [gr.update()] * 7+ return [gr.update()] * 9audio_file_list, audio_file_settings_list = get_file_list(state, unpack_audio_list(audio_files_paths), audio_files= True)if audio_file_selected >= 0:choice = audio_file_selected@@ -6474,7 +6474,8 @@ def generate_video(time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%Hh%Mm%Ss")save_prompt = original_prompts[0]if audio_only:- extension = "wav"+ audio_codec = server_config.get("audio_stand_alone_output_codec", "wav")+ extension = get_audio_codec_extension(audio_codec)output_dir = audio_save_pathelif is_image:extension = "jpg"@@ -6499,7 +6500,7 @@ def generate_video(BGRA_frames = Noneif audio_only:audio_path = os.path.join(output_dir, file_name)- write_wav_file(audio_path, sample.squeeze(0), output_audio_sampling_rate)+ audio_path = save_audio_file(audio_path, sample.squeeze(0), output_audio_sampling_rate, audio_codec)video_path = audio_pathelif is_image:image_path = os.path.join(output_dir, file_name)