Update to V1.4
Browse filesFiles changed (50)
- app.py+7-7
- fish_speech/configs/firefly_gan_vq.yaml+2-3
- fish_speech/configs/text2semantic_finetune.yaml+1-1
- fish_speech/i18n/README.mdAdded+27
- fish_speech/i18n/__init__.pyAdded+3
- fish_speech/i18n/core.pyAdded+40
- fish_speech/i18n/locale/en_US.jsonAdded+122
- fish_speech/i18n/locale/es_ES.jsonAdded+122
- fish_speech/i18n/locale/ja_JP.jsonAdded+123
- fish_speech/i18n/locale/pt_BR.jsonAdded+133
- fish_speech/i18n/locale/zh_CN.jsonAdded+122
- fish_speech/i18n/scan.pyAdded+122
- fish_speech/models/text2semantic/llama.py+27
- fish_speech/models/vqgan/__init__.py-3
- fish_speech/models/vqgan/modules/firefly.py+167-196
- fish_speech/models/vqgan/modules/fsq.py+4-27
- fish_speech/scheduler.py+19-1
- fish_speech/text/clean.py+1-1
- fish_speech/train.py+5-1
- fish_speech/utils/__init__.py+2
- fish_speech/utils/context.pyAdded+13
- fish_speech/utils/file.py-103
- fish_speech/webui/css/style.cssAdded+161
- fish_speech/webui/html/footer.htmlAdded+11
- fish_speech/webui/js/animate.jsAdded+69
- fish_speech/webui/launch_utils.pyAdded+120
- fish_speech/webui/manage.pyAdded+1237
- requirements.txt+2-1
- tools/api.py+93-135
- tools/commons.pyAdded+35
- tools/download_models.pyAdded+55
- tools/extract_model.pyAdded+21
- tools/file.pyAdded+125
- tools/llama/build_dataset.py+1-1
- tools/llama/generate.py+28-10
- tools/llama/merge_lora.py+1-1
- tools/llama/quantize.py+2-2
- tools/msgpack_api.pyAdded+34
- tools/post_api.pyAdded+205
- tools/sensevoice/README.mdAdded+59
- tools/sensevoice/__init__.pyAdded
- tools/sensevoice/auto_model.pyAdded+573
- tools/sensevoice/fun_asr.pyAdded+332
- tools/sensevoice/vad_utils.pyAdded+61
- tools/smart_pad.pyAdded+47
- tools/vqgan/create_train_split.py+1-1
- tools/vqgan/extract_vq.py+3-3
- tools/vqgan/inference.py+5-3
- tools/webui.pyAdded+619
- tools/whisper_asr.pyAdded+176
9 unmodified lines1011121314151629 unmodified lines46474849505152537 unmodified lines6162636465666768491 unmodified lines5605615625635645655665675685695705719 unmodified lines# Download if not existsos.makedirs("checkpoints", exist_ok=True)snapshot_download(repo_id="fishaudio/fish-speech-1.2-sft", local_dir="./checkpoints/fish-speech-1.2-sft")print("All checkpoints downloaded")29 unmodified linesHEADER_MD = """# Fish Speech## The demo in this space is version 1.2, Please check [Fish Audio](https://fish.audio) for the best model.## 该 Demo 为 Fish Speech 1.2 版本, 请在 [Fish Audio](https://fish.audio) 体验最新 DEMO.A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).由 [Fish Audio](https://fish.audio) 研发的基于 VQ-GAN 和 Llama 的多语种语音合成.7 unmodified linesWe are not responsible for any misuse of the model, please consider your local laws and regulations before using it.我们不对模型的任何滥用负责,请在使用之前考虑您当地的法律法规.The model running in this WebUI is Fish Speech V1.2 Medium SFT.在此 WebUI 中运行的模型是 Fish Speech V1.2 Medium SFT."""TEXTBOX_PLACEHOLDER = """Put your text here. 在此处输入文本."""491 unmodified linesparser.add_argument("--llama-checkpoint-path",type=Path,default="checkpoints/fish-speech-1.2-sft",)parser.add_argument("--decoder-checkpoint-path",type=Path,default="checkpoints/fish-speech-1.2-sft/firefly-gan-vq-fsq-4x1024-42hz-generator.pth",)parser.add_argument("--decoder-config-name", type=str, default="firefly_gan_vq")parser.add_argument("--device", type=str, default="cuda")9 unmodified lines1011121314151629 unmodified lines46474849505152537 unmodified lines6162636465666768491 unmodified lines5605615625635645655665675685695705719 unmodified lines# Download if not existsos.makedirs("checkpoints", exist_ok=True)snapshot_download(repo_id="fishaudio/fish-speech-1.4", local_dir="./checkpoints/fish-speech-1.4")print("All checkpoints downloaded")29 unmodified linesHEADER_MD = """# Fish Speech## The demo in this space is version 1.4, Please check [Fish Audio](https://fish.audio) for the best model.## 该 Demo 为 Fish Speech 1.4 版本, 请在 [Fish Audio](https://fish.audio) 体验最新 DEMO.A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).由 [Fish Audio](https://fish.audio) 研发的基于 VQ-GAN 和 Llama 的多语种语音合成.7 unmodified linesWe are not responsible for any misuse of the model, please consider your local laws and regulations before using it.我们不对模型的任何滥用负责,请在使用之前考虑您当地的法律法规.The model running in this WebUI is Fish Speech V1.4 Medium.在此 WebUI 中运行的模型是 Fish Speech V1.4 Medium."""TEXTBOX_PLACEHOLDER = """Put your text here. 在此处输入文本."""491 unmodified linesparser.add_argument("--llama-checkpoint-path",type=Path,default="checkpoints/fish-speech-1.4",)parser.add_argument("--decoder-checkpoint-path",type=Path,default="checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth",)parser.add_argument("--decoder-config-name", type=str, default="firefly_gan_vq")parser.add_argument("--device", type=str, default="cuda")
21 unmodified lines2223242526272829303132333421 unmodified linesresblock_dilation_sizes: [[1, 3, 5], [1, 3, 5], [1, 3, 5]]num_mels: 512upsample_initial_channel: 512use_template: falsepre_conv_kernel_size: 13post_conv_kernel_size: 13quantizer:_target_: fish_speech.models.vqgan.modules.fsq.DownsampleFiniteScalarQuantizeinput_dim: 512n_groups: 4n_codebooks: 1levels: [8, 5, 5, 5]downsample_factor: [2]21 unmodified lines22232425262728293031323321 unmodified linesresblock_dilation_sizes: [[1, 3, 5], [1, 3, 5], [1, 3, 5]]num_mels: 512upsample_initial_channel: 512pre_conv_kernel_size: 13post_conv_kernel_size: 13quantizer:_target_: fish_speech.models.vqgan.modules.fsq.DownsampleFiniteScalarQuantizeinput_dim: 512n_groups: 8n_codebooks: 1levels: [8, 5, 5, 5]downsample_factor: [2, 2]
3 unmodified lines456789103 unmodified linesproject: text2semantic_finetune_dual_armax_length: 4096pretrained_ckpt_path: checkpoints/fish-speech-1.2-sft# Lightning Trainertrainer:3 unmodified lines456789103 unmodified linesproject: text2semantic_finetune_dual_armax_length: 4096pretrained_ckpt_path: checkpoints/fish-speech-1.4# Lightning Trainertrainer:
123456789101112131415161718192021222324252627## i18n Folder Attribution
The `i18n` folder within the `fish_speech` directory contains files initially sourced from the RVC project. In compliance with the MIT license under which these files were released, we acknowledge the original authors and sources below:
### fish_speech/i18n/core.py
**Related code from RVC:**[https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/blob/83d6a64e675d9bbd6e92ee450c5f807ed2bb54d8/i18n/i18n.py](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/blob/83d6a64e675d9bbd6e92ee450c5f807ed2bb54d8/i18n/i18n.py)
**Initial commit:**add localization(添加本地化) [RVC-Project/Retrieval-based-Voice-Conversion-WebUI#35](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/pull/35)
**Initial author:**[@L4Ph](https://github.com/L4Ph)
### fish_speech/i18n/scan.py
**Related code from RVC:**[https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/blob/83d6a64e675d9bbd6e92ee450c5f807ed2bb54d8/i18n/scan_i18n.py](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/blob/83d6a64e675d9bbd6e92ee450c5f807ed2bb54d8/i18n/scan_i18n.py)
**Initial commit:**File for detecting i18n missing keys [RVC-Project/Retrieval-based-Voice-Conversion-WebUI#1058](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/pull/1058)
**Initial author:**[@towzeur](https://github.com/towzeur)
We appreciate the contributions of the RVC project and its authors.123from .core import i18n
__all__ = ["i18n"]12345678910111213141516171819202122232425262728293031323334353637383940import jsonimport localefrom pathlib import Path
I18N_FILE_PATH = Path(__file__).parent / "locale"DEFAULT_LANGUAGE = "en_US"
def load_language_list(language): with open(I18N_FILE_PATH / f"{language}.json", "r", encoding="utf-8") as f: language_list = json.load(f)
return language_list
class I18nAuto: def __init__(self): i18n_file = Path(".locale")
if i18n_file.exists(): with open(i18n_file, "r", encoding="utf-8") as f: language = f.read().strip() else: # getlocale can't identify the system's language ((None, None)) language = locale.getdefaultlocale()[0]
if (I18N_FILE_PATH / f"{language}.json").exists() is False: language = DEFAULT_LANGUAGE
self.language = language self.language_map = load_language_list(language)
def __call__(self, key): return self.language_map.get(key, key)
def __repr__(self): return "Use Language: " + self.language
i18n = I18nAuto()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122{ "16-mixed is recommended for 10+ series GPU": "16-mixed is recommended for 10+ series GPU", "5 to 10 seconds of reference audio, useful for specifying speaker.": "5 to 10 seconds of reference audio, useful for specifying speaker.", "A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).": "A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).", "Accumulate Gradient Batches": "Accumulate Gradient Batches", "Add to Processing Area": "Add to Processing Area", "Added path successfully!": "Added path successfully!", "Advanced Config": "Advanced Config", "Base LLAMA Model": "Base LLAMA Model", "Batch Inference": "Batch Inference", "Batch Size": "Batch Size", "Changing with the Model Path": "Changing with the Model Path", "Chinese": "Chinese", "Compile Model": "Compile Model", "Compile the model can significantly reduce the inference time, but will increase cold start time": "Compile the model can significantly reduce the inference time, but will increase cold start time", "Copy": "Copy", "Data Preprocessing": "Data Preprocessing", "Data Preprocessing Path": "Data Preprocessing Path", "Data Source": "Data Source", "Decoder Model Config": "Decoder Model Config", "Decoder Model Path": "Decoder Model Path", "Disabled": "Disabled", "Enable Reference Audio": "Enable Reference Audio", "English": "English", "Error Message": "Error Message", "File Preprocessing": "File Preprocessing", "Generate": "Generate", "Generated Audio": "Generated Audio", "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format": "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format", "Infer interface is closed": "Infer interface is closed", "Inference Configuration": "Inference Configuration", "Inference Server Configuration": "Inference Server Configuration", "Inference Server Error": "Inference Server Error", "Inferring interface is launched at {}": "Inferring interface is launched at {}", "Initial Learning Rate": "Initial Learning Rate", "Input Audio & Source Path for Transcription": "Input Audio & Source Path for Transcription", "Input Text": "Input Text", "Invalid path: {}": "Invalid path: {}", "It is recommended to use CUDA, if you have low configuration, use CPU": "It is recommended to use CUDA, if you have low configuration, use CPU", "Iterative Prompt Length, 0 means off": "Iterative Prompt Length, 0 means off", "Japanese": "Japanese", "LLAMA Configuration": "LLAMA Configuration", "LLAMA Model Config": "LLAMA Model Config", "LLAMA Model Path": "LLAMA Model Path", "Labeling Device": "Labeling Device", "LoRA Model to be merged": "LoRA Model to be merged", "Maximum Audio Duration": "Maximum Audio Duration", "Maximum Length per Sample": "Maximum Length per Sample", "Maximum Training Steps": "Maximum Training Steps", "Maximum tokens per batch, 0 means no limit": "Maximum tokens per batch, 0 means no limit", "Merge": "Merge", "Merge LoRA": "Merge LoRA", "Merge successfully": "Merge successfully", "Minimum Audio Duration": "Minimum Audio Duration", "Model Output Path": "Model Output Path", "Model Size": "Model Size", "Move": "Move", "Move files successfully": "Move files successfully", "No audio generated, please check the input text.": "No audio generated, please check the input text.", "No selected options": "No selected options", "Number of Workers": "Number of Workers", "Open Inference Server": "Open Inference Server", "Open Labeler WebUI": "Open Labeler WebUI", "Open Tensorboard": "Open Tensorboard", "Opened labeler in browser": "Opened labeler in browser", "Optional Label Language": "Optional Label Language", "Optional online ver": "Optional online ver", "Output Path": "Output Path", "Path error, please check the model file exists in the corresponding path": "Path error, please check the model file exists in the corresponding path", "Precision": "Precision", "Probability of applying Speaker Condition": "Probability of applying Speaker Condition", "Put your text here.": "Put your text here.", "Reference Audio": "Reference Audio", "Reference Text": "Reference Text", "Related code and weights are released under CC BY-NC-SA 4.0 License.": "Related code and weights are released under CC BY-NC-SA 4.0 License.", "Remove Selected Data": "Remove Selected Data", "Removed path successfully!": "Removed path successfully!", "Repetition Penalty": "Repetition Penalty", "Save model every n steps": "Save model every n steps", "Select LLAMA ckpt": "Select LLAMA ckpt", "Select VITS ckpt": "Select VITS ckpt", "Select VQGAN ckpt": "Select VQGAN ckpt", "Select source file processing method": "Select source file processing method", "Select the model to be trained (Depending on the Tab page you are on)": "Select the model to be trained (Depending on the Tab page you are on)", "Selected: {}": "Selected: {}", "Speaker": "Speaker", "Speaker is identified by the folder name": "Speaker is identified by the folder name", "Start Training": "Start Training", "Streaming Audio": "Streaming Audio", "Streaming Generate": "Streaming Generate", "Tensorboard Host": "Tensorboard Host", "Tensorboard Log Path": "Tensorboard Log Path", "Tensorboard Port": "Tensorboard Port", "Tensorboard interface is closed": "Tensorboard interface is closed", "Tensorboard interface is launched at {}": "Tensorboard interface is launched at {}", "Text is too long, please keep it under {} characters.": "Text is too long, please keep it under {} characters.", "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list.": "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list.", "Training Configuration": "Training Configuration", "Training Error": "Training Error", "Training stopped": "Training stopped", "Type name of the speaker": "Type name of the speaker", "Type the path or select from the dropdown": "Type the path or select from the dropdown", "Use LoRA": "Use LoRA", "Use LoRA can save GPU memory, but may reduce the quality of the model": "Use LoRA can save GPU memory, but may reduce the quality of the model", "Use filelist": "Use filelist", "Use large for 10G+ GPU, medium for 5G, small for 2G": "Use large for 10G+ GPU, medium for 5G, small for 2G", "VITS Configuration": "VITS Configuration", "VQGAN Configuration": "VQGAN Configuration", "Validation Batch Size": "Validation Batch Size", "View the status of the preprocessing folder (use the slider to control the depth of the tree)": "View the status of the preprocessing folder (use the slider to control the depth of the tree)", "We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.": "We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.", "WebUI Host": "WebUI Host", "WebUI Port": "WebUI Port", "Whisper Model": "Whisper Model", "You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1).": "You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1).", "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU": "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU", "latest": "latest", "new": "new", "Realtime Transform Text": "Realtime Transform Text", "Normalization Result Preview (Currently Only Chinese)": "Normalization Result Preview (Currently Only Chinese)", "Text Normalization": "Text Normalization"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122{ "16-mixed is recommended for 10+ series GPU": "se recomienda 16-mixed para GPU de la serie 10+", "5 to 10 seconds of reference audio, useful for specifying speaker.": "5 a 10 segundos de audio de referencia, útil para especificar el hablante.", "A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).": "Un modelo de texto a voz basado en VQ-GAN y Llama desarrollado por [Fish Audio](https://fish.audio).", "Accumulate Gradient Batches": "Acumular lotes de gradientes", "Add to Processing Area": "Agregar al Área de Procesamiento", "Added path successfully!": "¡Ruta agregada exitosamente!", "Advanced Config": "Configuración Avanzada", "Base LLAMA Model": "Modelo Base LLAMA", "Batch Inference": "Inferencia por Lote", "Batch Size": "Tamaño del Lote", "Changing with the Model Path": "Cambiando con la Ruta del Modelo", "Chinese": "Chino", "Compile Model": "Compilar Modelo", "Compile the model can significantly reduce the inference time, but will increase cold start time": "Compilar el modelo puede reducir significativamente el tiempo de inferencia, pero aumentará el tiempo de inicio en frío", "Copy": "Copiar", "Data Preprocessing": "Preprocesamiento de Datos", "Data Preprocessing Path": "Ruta de Preprocesamiento de Datos", "Data Source": "Fuente de Datos", "Decoder Model Config": "Configuración del modelo decodificador", "Decoder Model Path": "Ruta del modelo decodificador", "Disabled": "Desactivado", "Enable Reference Audio": "Habilitar Audio de Referencia", "English": "Inglés", "Error Message": "Mensaje de Error", "File Preprocessing": "Preprocesamiento de Archivos", "Generate": "Generar", "Generated Audio": "Audio Generado", "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format": "Si no hay texto correspondiente para el audio, aplique ASR para asistencia, soporte para formato .txt o .lab", "Infer interface is closed": "La interfaz de inferencia está cerrada", "Inference Configuration": "Configuración de Inferencia", "Inference Server Configuration": "Configuración del Servidor de Inferencia", "Inference Server Error": "Error del Servidor de Inferencia", "Inferring interface is launched at {}": "La interfaz de inferencia se ha lanzado en {}", "Initial Learning Rate": "Tasa de Aprendizaje Inicial", "Input Audio & Source Path for Transcription": "Audio de Entrada y Ruta de Origen para Transcripción", "Input Text": "Texto de Entrada", "Invalid path: {}": "Ruta inválida: {}", "It is recommended to use CUDA, if you have low configuration, use CPU": "Se recomienda usar CUDA, si tiene una configuración baja, use CPU", "Iterative Prompt Length, 0 means off": "Longitud de la Indicación Iterativa, 0 significa apagado", "Japanese": "Japonés", "LLAMA Configuration": "Configuración de LLAMA", "LLAMA Model Config": "Configuración del Modelo LLAMA", "LLAMA Model Path": "Ruta del Modelo LLAMA", "Labeling Device": "Dispositivo de Etiquetado", "LoRA Model to be merged": "Modelo LoRA a fusionar", "Maximum Audio Duration": "Duración máxima de audio", "Maximum Length per Sample": "Longitud Máxima por Muestra", "Maximum Training Steps": "Pasos Máximos de Entrenamiento", "Maximum tokens per batch, 0 means no limit": "Máximo de tokens por lote, 0 significa sin límite", "Merge": "Fusionar", "Merge LoRA": "Fusionar LoRA", "Merge successfully": "Fusionado exitosamente", "Minimum Audio Duration": "Duración mínima de audio", "Model Output Path": "Ruta de Salida del Modelo", "Model Size": "Tamaño del Modelo", "Move": "Mover", "Move files successfully": "Archivos movidos exitosamente", "No audio generated, please check the input text.": "No se generó audio, por favor verifique el texto de entrada.", "No selected options": "No hay opciones seleccionadas", "Number of Workers": "Número de Trabajadores", "Open Inference Server": "Abrir Servidor de Inferencia", "Open Labeler WebUI": "Abrir Interfaz Web del Etiquetador", "Open Tensorboard": "Abrir Tensorboard", "Opened labeler in browser": "Se abrió el etiquetador en el navegador", "Optional Label Language": "Idioma de Etiquetado Opcional", "Optional online ver": "Ver en línea opcional", "Output Path": "Ruta de Salida", "Path error, please check the model file exists in the corresponding path": "Error de ruta, por favor verifique que el archivo del modelo exista en la ruta correspondiente", "Precision": "Precisión", "Probability of applying Speaker Condition": "Probabilidad de aplicar Condición de Hablante", "Put your text here.": "Ponga su texto aquí.", "Reference Audio": "Audio de Referencia", "Reference Text": "Texto de Referencia", "Related code and weights are released under CC BY-NC-SA 4.0 License.": "El código relacionado y los pesos se publican bajo la Licencia CC BY-NC-SA 4.0.", "Remove Selected Data": "Eliminar Datos Seleccionados", "Removed path successfully!": "¡Ruta eliminada exitosamente!", "Repetition Penalty": "Penalización por Repetición", "Save model every n steps": "Guardar modelo cada n pasos", "Select LLAMA ckpt": "Seleccionar punto de control LLAMA", "Select VITS ckpt": "Seleccionar punto de control VITS", "Select VQGAN ckpt": "Seleccionar punto de control VQGAN", "Select source file processing method": "Seleccione el método de procesamiento de archivos fuente", "Select the model to be trained (Depending on the Tab page you are on)": "Seleccione el modelo a entrenar (Dependiendo de la pestaña en la que se encuentre)", "Selected: {}": "Seleccionado: {}", "Speaker": "Hablante", "Speaker is identified by the folder name": "El hablante se identifica por el nombre de la carpeta", "Start Training": "Iniciar Entrenamiento", "Streaming Audio": "transmisión de audio", "Streaming Generate": "síntesis en flujo", "Tensorboard Host": "Host de Tensorboard", "Tensorboard Log Path": "Ruta de Registro de Tensorboard", "Tensorboard Port": "Puerto de Tensorboard", "Tensorboard interface is closed": "La interfaz de Tensorboard está cerrada", "Tensorboard interface is launched at {}": "La interfaz de Tensorboard se ha lanzado en {}", "Text is too long, please keep it under {} characters.": "El texto es demasiado largo, por favor manténgalo por debajo de {} caracteres.", "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list.": "La ruta de la carpeta de entrada a la izquierda o la lista de archivos. Ya sea que esté marcado o no, se utilizará para el entrenamiento posterior en esta lista.", "Training Configuration": "Configuración de Entrenamiento", "Training Error": "Error de Entrenamiento", "Training stopped": "Entrenamiento detenido", "Type name of the speaker": "Escriba el nombre del hablante", "Type the path or select from the dropdown": "Escriba la ruta o seleccione de la lista desplegable", "Use LoRA": "Usar LoRA", "Use LoRA can save GPU memory, but may reduce the quality of the model": "Usar LoRA puede ahorrar memoria GPU, pero puede reducir la calidad del modelo", "Use filelist": "Usar lista de archivos", "Use large for 10G+ GPU, medium for 5G, small for 2G": "Use grande para GPU de 10G+, mediano para 5G, pequeño para 2G", "VITS Configuration": "Configuración de VITS", "VQGAN Configuration": "Configuración de VQGAN", "Validation Batch Size": "Tamaño del Lote de Validación", "View the status of the preprocessing folder (use the slider to control the depth of the tree)": "Vea el estado de la carpeta de preprocesamiento (use el control deslizante para controlar la profundidad del árbol)", "We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.": "No somos responsables de ningún mal uso del modelo, por favor considere sus leyes y regulaciones locales antes de usarlo.", "WebUI Host": "Host de WebUI", "WebUI Port": "Puerto de WebUI", "Whisper Model": "Modelo Whisper", "You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1).": "Puede encontrar el código fuente [aquí](https://github.com/fishaudio/fish-speech) y los modelos [aquí](https://huggingface.co/fishaudio/fish-speech-1).", "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU": "Se recomienda bf16-true para GPU de la serie 30+, se recomienda 16-mixed para GPU de la serie 10+", "latest": "más reciente", "new": "nuevo", "Realtime Transform Text": "Transformación de Texto en Tiempo Real", "Normalization Result Preview (Currently Only Chinese)": "Vista Previa del Resultado de Normalización (Actualmente Solo Chino)", "Text Normalization": "Normalización de Texto"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123{ "16-mixed is recommended for 10+ series GPU": "10シリーズ以降のGPUには16-mixedをお勧めします", "5 to 10 seconds of reference audio, useful for specifying speaker.": "話者を指定するのに役立つ、5~10秒のリファレンスオーディオ。", "A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).": "[Fish Audio](https://fish.audio)が開発したVQ-GANとLlamaに基づくテキスト音声合成モデル。", "Accumulate Gradient Batches": "勾配バッチの累積", "Add to Processing Area": "処理エリアに追加", "Added path successfully!": "パスの追加に成功しました!", "Advanced Config": "詳細設定", "Base LLAMA Model": "基本LLAMAモデル", "Batch Inference": "バッチ推論", "Batch Size": "バッチサイズ", "Changing with the Model Path": "モデルのパスに伴って変化する", "Chinese": "中国語", "Compile Model": "モデルのコンパイル", "Compile the model can significantly reduce the inference time, but will increase cold start time": "モデルをコンパイルすると推論時間を大幅に短縮できますが、コールドスタート時間が長くなります", "Copy": "コピー", "Data Preprocessing": "データ前処理", "Data Preprocessing Path": "データ前処理パス", "Data Source": "データソース", "Decoder Model Config": "デコーダーモデルの構成", "Decoder Model Path": "デコーダーモデルのパス", "Disabled": "無効", "Enable Reference Audio": "リファレンスオーディオを有効にする", "English": "英語", "Error Message": "エラーメッセージ", "File Preprocessing": "文書前处理", "Generate": "生成", "Generated Audio": "生成されたオーディオ", "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format": "音声に対応するテキストがない場合は、ASRを適用してサポートします。.txtまたは.lab形式をサポートしています", "Infer interface is closed": "推論インターフェースが閉じられています", "Inference Configuration": "推論設定", "Inference Server Configuration": "推論サーバー設定", "Inference Server Error": "推論サーバーエラー", "Inferring interface is launched at {}": "推論インターフェースが{}で起動しました", "Initial Learning Rate": "初期学習率", "Input Audio & Source Path for Transcription": "入力オーディオと文字起こしのソースパス", "Input Text": "入力テキスト", "Invalid path: {}": "無効なパス: {}", "It is recommended to use CUDA, if you have low configuration, use CPU": "CUDAの使用をお勧めします。低い構成の場合はCPUを使用してください", "Iterative Prompt Length, 0 means off": "反復プロンプト長。0はオフを意味します", "Japanese": "日本語", "LLAMA Configuration": "LLAMA設定", "LLAMA Model Config": "LLAMAモデル設定", "LLAMA Model Path": "LLAMAモデルパス", "Labeling Device": "ラベリングデバイス", "LoRA Model to be merged": "マージするLoRAモデル", "Maximum Audio Duration": "最大オーディオの長さ", "Maximum Length per Sample": "サンプルあたりの最大長", "Maximum Training Steps": "最大トレーニングステップ数", "Maximum tokens per batch, 0 means no limit": "バッチあたりの最大トークン数。0は制限なしを意味します", "Merge": "マージ", "Merge LoRA": "LoRAのマージ", "Merge successfully": "マージに成功しました", "Minimum Audio Duration": "最小オーディオの長さ", "Model Output Path": "モデル出力パス", "Model Size": "モデルサイズ", "Move": "移動", "Move files successfully": "ファイルの移動に成功しました", "No audio generated, please check the input text.": "オーディオが生成されていません。入力テキストを確認してください。", "No selected options": "選択されたオプションはありません", "Number of Workers": "ワーカー数", "Open Inference Server": "推論サーバーを開く", "Open Labeler WebUI": "ラベラーWebUIを開く", "Open Tensorboard": "Tensorboardを開く", "Opened labeler in browser": "ブラウザでラベラーを開きました", "Optional Label Language": "オプションのラベル言語", "Optional online ver": "オプションのオンラインバージョン", "Output Path": "出力パス", "Path error, please check the model file exists in the corresponding path": "パスエラー。対応するパスにモデルファイルが存在するか確認してください", "Precision": "精度", "Probability of applying Speaker Condition": "話者条件を適用する確率", "Put your text here.": "ここにテキストを入力してください。", "Reference Audio": "リファレンスオーディオ", "Reference Text": "リファレンステキスト", "Related code and weights are released under CC BY-NC-SA 4.0 License.": "関連コードと重みはCC BY-NC-SA 4.0ライセンスの下でリリースされます。", "Remove Selected Data": "選択したデータを削除", "Removed path successfully!": "パスの削除に成功しました!", "Repetition Penalty": "反復ペナルティ", "Save model every n steps": "nステップごとにモデルを保存", "Select LLAMA ckpt": " LLAMA チェックポイントを選択", "Select VITS ckpt": "VITS チェックポイントを選択", "Select VQGAN ckpt": "VQGAN チェックポイントを選択", "Select source file processing method": "ソースファイルの処理方法を選択", "Select the model to be trained (Depending on the Tab page you are on)": "タブページに応じてトレーニングするモデルを選択してください", "Selected: {}": "選択済み: {}", "Speaker": "話者", "Speaker is identified by the folder name": "話者はフォルダ名で識別されます", "Start Training": "トレーニング開始", "Streaming Audio": "ストリーミングオーディオ", "Streaming Generate": "ストリーミング合成", "Tensorboard Host": "Tensorboardホスト", "Tensorboard Log Path": "Tensorboardログパス", "Tensorboard Port": "Tensorboardポート", "Tensorboard interface is closed": "Tensorboardインターフェースが閉じられています", "Tensorboard interface is launched at {}": "Tensorboardインターフェースが{}で起動されました", "Text is too long, please keep it under {} characters.": "テキストが長すぎます。{}文字以内に抑えてください。", "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list.": "左側の入力フォルダまたはファイルリストのパス。チェックの有無にかかわらず、このリストの後続のトレーニングに使用されます。", "Training Configuration": "トレーニング設定", "Training Error": "トレーニングエラー", "Training stopped": "トレーニングが停止しました", "Type name of the speaker": "話者の名前を入力", "Type the path or select from the dropdown": "パスを入力するか、ドロップダウンから選択してください", "Use LoRA": "LoRAを使用", "Use LoRA can save GPU memory, but may reduce the quality of the model": "LoRAを使用するとGPUメモリを節約できますが、モデルの品質が低下する可能性があります", "Use filelist": "ファイルリストを使用", "Use large for 10G+ GPU, medium for 5G, small for 2G": "10G以上のGPUには大、5Gには中、2Gには小を使用してください", "VITS Configuration": "VITS の構成", "VQGAN Configuration": "VQGAN の構成", "Validation Batch Size": "検証バッチサイズ", "View the status of the preprocessing folder (use the slider to control the depth of the tree)": "前処理フォルダの状態を表示(スライダーを使用してツリーの深さを制御)", "We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.": "モデルの誤用については一切責任を負いません。使用する前に、現地の法律と規制を考慮してください。", "WebUI Host": "WebUIホスト", "WebUI Port": "WebUIポート", "Whisper Model": "Whisperモデル", "You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1).": "ソースコードは[こちら](https://github.com/fishaudio/fish-speech)、モデルは[こちら](https://huggingface.co/fishaudio/fish-speech-1)にあります。", "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU": "30シリーズ以降のGPUにはbf16-trueを、10シリーズ以降のGPUには16-mixedをお勧めします", "latest": "最新", "new": "新規", "Realtime Transform Text": "リアルタイム変換テキスト", "Normalization Result Preview (Currently Only Chinese)": "正規化結果プレビュー(現在は中国語のみ)", "Text Normalization": "テキスト正規化"
}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133{ "5 to 10 seconds of reference audio, useful for specifying speaker.": "5 a 10 segundos de áudio de referência, útil para especificar o orador.", "A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).": "Um modelo de texto para fala baseado em VQ-GAN e Llama desenvolvido por [Fish Audio](https://fish.audio).", "Accumulate Gradient Batches": "Acumular Lotes de Gradiente", "Add to Processing Area": "Adicionar à Área de Processamento", "Added path successfully!": "Caminho adicionado com sucesso!", "Advanced Config": "Configuração Avançada", "Base LLAMA Model": "Modelo LLAMA Base", "Batch Inference": "Inferência em Lote", "Batch Size": "Tamanho do Lote", "Changing with the Model Path": "Alterando com o Caminho do Modelo",
"Compile Model": "Compilar Modelo", "Compile the model can significantly reduce the inference time, but will increase cold start time": "Compilar o modelo pode reduzir significativamente o tempo de inferência, mas aumentará a latência inicial", "Copy": "Copiar", "Data Preprocessing": "Pré-processamento de Dados", "Data Preprocessing Path": "Caminho de Pré-processamento de Dados", "Data Source": "Fonte de Dados", "Decoder Model Config": "Configuração do Modelo Decodificador", "Decoder Model Path": "Caminho do Modelo Decodificador", "Disabled": "Desativado", "Enable Initial Prompt": "Habilitar Prompt Inicial", "Enable Reference Audio": "Habilitar Áudio de Referência", "English": "Inglês", "Japanese": "Japonês", "Chinese": "Chinês", "Portuguese": "Português", "Spanish": "Espanhol", "Error Message": "Mensagem de Erro", "Faster Whisper, Up to 5g GPU memory usage": "Faster Whisper (Usa até 5 GB de vRAM)", "File Preprocessing": "Pré-processamento de Arquivos", "Generate": "Gerar", "Generated Audio": "Áudio Gerado", "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format": "Se não houver texto correspondente ao áudio, utilize o ASR para assistência (formatos .txt ou .lab)", "Infer interface is closed": "A interface de inferência foi fechada", "Inference Configuration": "Configuração de Inferência", "Inference Server Configuration": "Configuração do Servidor de Inferência", "Inference Server Error": "Erro do Servidor de Inferência", "Inferring interface is launched at {}": "A interface de inferência foi iniciada em {}", "Initial Learning Rate": "Taxa de Aprendizagem Inicial", "Initial Prompt": "Prompt Inicial", "Initial prompt can provide contextual or vocabulary-specific guidance to the model.": "O prompt inicial pode fornecer orientação contextual ou específica de vocabulário para o modelo.", "Input Audio & Source Path for Transcription": "Entrada de Áudio/Caminho de Origem para Transcrição", "Input Text": "Texto de Entrada", "Invalid path: {}": "Caminho inválido: {}", "It is recommended to use CUDA, if you have low configuration, use CPU": "Para GPUs Nvidia é recomendado usar CUDA. Se não tiver uma GPU Nvidia, use CPU", "Iterative Prompt Length, 0 means off": "Comprimento do Prompt Iterativo (0 = desativado)", "LLAMA Configuration": "Configuração do LLAMA", "LLAMA Model Config": "Configuração do Modelo LLAMA", "LLAMA Model Path": "Caminho do Modelo LLAMA", "Labeling Device": "Dispositivo de Rotulagem", "LoRA Model to be merged": "Modelo LoRA para mesclagem", "Maximum Length per Sample": "Comprimento Máximo por Amostra", "Maximum Training Steps": "Etapas Máximas de Treinamento", "Maximum tokens per batch, 0 means no limit": "Número máximo de tokens por lote, 0 significa sem limite", "Merge": "Mesclar", "Merge LoRA": "Mesclar LoRA", "Merge successfully": "Mesclado com sucesso", "Model Output Path": "Caminho de Saída do Modelo", "Model Quantization": "Quantização do Modelo", "Model Size": "Tamanho do Modelo", "Move": "Mover", "Move files successfully": "Arquivos movidos com sucesso", "No audio generated, please check the input text.": "Nenhum áudio gerado, verifique o texto de entrada.", "No selected options": "Nenhuma opção selecionada", "Normalization Result Preview (Currently Only Chinese)": "Pré-visualização do Resultado da Normalização (Atualmente Apenas Chinês)", "Number of Workers": "Número de Processos", "Open Inference Server": "Abrir Servidor de Inferência", "Open Labeler WebUI": "Abrir WebUI de Rotulagem", "Open Tensorboard": "Abrir Tensorboard", "Opened labeler in browser": "WebUI de rotulagem aberta no navegador", "Optional Label Language": "Idioma do Rótulo (Opcional)", "Optional online ver": "Versão online (opcional)", "Output Path": "Caminho de Saída", "Path error, please check the model file exists in the corresponding path": "Erro de caminho, verifique se o arquivo do modelo existe no caminho correspondente", "Post-quantification Precision": "Precisão Pós-quantização", "Precision": "Precisão", "Probability of applying Speaker Condition": "Probabilidade de Aplicar Condição de Orador", "Put your text here.": "Insira seu texto aqui.", "Quantify": "Quantizar", "Quantify successfully": "Quantizado com sucesso", "Realtime Transform Text": "Transformar Texto em Tempo Real", "Reference Audio": "Áudio de Referência", "Reference Text": "Texto de Referência", "warning": "Aviso", "Pre-processing begins...": "O pré-processamento começou!", "Related code and weights are released under CC BY-NC-SA 4.0 License.": "O código relacionado e os pesos são licenciados sob a Licença CC BY-NC-SA 4.0.", "Remove Selected Data": "Remover Dados Selecionados", "Removed path successfully!": "Caminho removido com sucesso!", "Repetition Penalty": "Penalidade de Repetição", "Save model every n steps": "Salvar modelo a cada n etapas", "Select LLAMA ckpt": "Selecionar .ckpt do LLAMA", "Select source file processing method": "Escolha como processar o arquivo de origem", "Select the model to be trained (Depending on the Tab page you are on)": "Selecione o modelo para o treinamento (dependendo da aba em que você está)", "Selected: {}": "Selecionado: {}", "Speaker is identified by the folder name": "O orador é identificado pelo nome da pasta", "Start Training": "Iniciar Treinamento", "Streaming Audio": "Áudio em Streaming", "Streaming Generate": "Geração em Streaming", "Tensorboard Host": "Host do Tensorboard", "Tensorboard Log Path": "Caminho de Log do Tensorboard", "Tensorboard Port": "Porta do Tensorboard", "Tensorboard interface is closed": "A interface do Tensorboard está fechada", "Tensorboard interface is launched at {}": "A interface do Tensorboard foi iniciada em {}", "Text Normalization": "Normalização de Texto", "Text is too long, please keep it under {} characters.": "O texto é muito longo. Mantenha-o com menos de {} caracteres.", "The lower the quantitative precision, the more the effectiveness may decrease, but the greater the efficiency will increase": "Quanto menor a precisão quantitativa, mais a eficácia pode diminuir, mas maior será o aumento da eficiência", "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list.": "O caminho da pasta de entrada à esquerda ou a lista de arquivos. Independentemente de estar marcada ou não, ela será utilizada para o treinamento subsequente nesta lista.", "Training Configuration": "Configuração de Treinamento", "Training Error": "Erro de Treinamento", "Training stopped": "Treinamento interrompido!", "Type the path or select from the dropdown": "Digite o caminho ou selecione no menu suspenso", "Use LoRA": "Usar LoRA", "Use LoRA can save GPU memory, but may reduce the quality of the model": "O uso de LoRAs pode economizar memória da GPU, mas também pode reduzir a qualidade", "Use filelist": "Usar lista de arquivos", "VQGAN Configuration": "Configuração do VQGAN", "View the status of the preprocessing folder (use the slider to control the depth of the tree)": "Visualizar o status da pasta de pré-processamento (use o controle deslizante para controlar a profundidade da árvore)", "We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.": "Não nos responsabilizamos por qualquer uso indevido do modelo. Por favor, considere as leis e regulamentações locais antes de usá-lo.", "WebUI Host": "Host da WebUI", "WebUI Port": "Porta da WebUI", "Whisper Model": "Modelo Whisper", "You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1).": "Você pode encontrar o código fonte [aqui](https://github.com/fishaudio/fish-speech) e os modelos [aqui](https://huggingface.co/fishaudio/fish-speech-1).", "auto": "automático", "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU": "bf16-true é recomendado para GPUs da série 30+, 16-mixed é recomendado para GPUs da série 10+", "latest": "mais recente", "new": "novo", "This audio introduces the basic concepts and applications of artificial intelligence and machine learning.": "Este áudio introduz os conceitos básicos e aplicações de inteligência artificial e aprendizado de máquina.", "You don't need to train this model!": "Não é necessário treinar este modelo!", "Yes": "Sim", "No": "Não", "version:": "versão:", "author:": "autor:"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122{ "16-mixed is recommended for 10+ series GPU": "10+ 系列 GPU 建议使用 16-mixed", "5 to 10 seconds of reference audio, useful for specifying speaker.": "5 到 10 秒的参考音频,适用于指定音色。", "A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).": "由 [Fish Audio](https://fish.audio) 研发的基于 VQ-GAN 和 Llama 的多语种语音合成.", "Accumulate Gradient Batches": "梯度累积批次", "Add to Processing Area": "加入处理区", "Added path successfully!": "添加路径成功!", "Advanced Config": "高级参数", "Base LLAMA Model": "基础 LLAMA 模型", "Batch Inference": "批量推理", "Batch Size": "批次大小", "Changing with the Model Path": "随模型路径变化", "Chinese": "中文", "Compile Model": "编译模型", "Compile the model can significantly reduce the inference time, but will increase cold start time": "编译模型可以显著减少推理时间,但会增加冷启动时间", "Copy": "复制", "Data Preprocessing": "数据预处理", "Data Preprocessing Path": "数据预处理路径", "Data Source": "数据源", "Decoder Model Config": "解码器模型配置", "Decoder Model Path": "解码器模型路径", "Disabled": "禁用", "Enable Reference Audio": "启用参考音频", "English": "英文", "Error Message": "错误信息", "File Preprocessing": "文件预处理", "Generate": "生成", "Generated Audio": "音频", "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format": "如果音频没有对应的文本,可以应用 ASR 辅助,支持 .txt 或 .lab 格式", "Infer interface is closed": "推理界面已关闭", "Inference Configuration": "推理配置", "Inference Server Configuration": "推理服务器配置", "Inference Server Error": "推理服务器错误", "Inferring interface is launched at {}": "推理界面已在 {} 上启动", "Initial Learning Rate": "初始学习率", "Input Audio & Source Path for Transcription": "输入音频和转录源路径", "Input Text": "输入文本", "Invalid path: {}": "无效路径: {}", "It is recommended to use CUDA, if you have low configuration, use CPU": "建议使用 CUDA,如果配置较低,使用 CPU", "Iterative Prompt Length, 0 means off": "迭代提示长度,0 表示关闭", "Japanese": "日文", "LLAMA Configuration": "LLAMA 配置", "LLAMA Model Config": "LLAMA 模型配置", "LLAMA Model Path": "LLAMA 模型路径", "Labeling Device": "标注加速设备", "LoRA Model to be merged": "要合并的 LoRA 模型", "Maximum Audio Duration": "最大音频时长", "Maximum Length per Sample": "每个样本的最大长度", "Maximum Training Steps": "最大训练步数", "Maximum tokens per batch, 0 means no limit": "每批最大令牌数,0 表示无限制", "Merge": "合并", "Merge LoRA": "合并 LoRA", "Merge successfully": "合并成功", "Minimum Audio Duration": "最小音频时长", "Model Output Path": "模型输出路径", "Model Size": "模型规模", "Move": "移动", "Move files successfully": "移动文件成功", "No audio generated, please check the input text.": "没有生成音频,请检查输入文本.", "No selected options": "没有选择的选项", "Number of Workers": "数据加载进程数", "Open Inference Server": "打开推理服务器", "Open Labeler WebUI": "打开标注工具", "Open Tensorboard": "打开 Tensorboard", "Opened labeler in browser": "在浏览器中打开标注工具", "Optional Label Language": "[可选] 标注语言", "Optional online ver": "[可选] 使用在线版", "Output Path": "输出路径", "Path error, please check the model file exists in the corresponding path": "路径错误,请检查模型文件是否存在于相应路径", "Precision": "精度", "Probability of applying Speaker Condition": "应用说话人条件的概率", "Put your text here.": "在此处输入文本.", "Reference Audio": "参考音频", "Reference Text": "参考文本", "Related code and weights are released under CC BY-NC-SA 4.0 License.": "相关代码和权重使用 CC BY-NC-SA 4.0 许可证发布.", "Remove Selected Data": "移除选中数据", "Removed path successfully!": "移除路径成功!", "Repetition Penalty": "重复惩罚", "Save model every n steps": "每 n 步保存模型", "Select LLAMA ckpt": "选择 LLAMA 检查点", "Select VITS ckpt": "选择 VITS 检查点", "Select VQGAN ckpt": "选择 VQGAN 检查点", "Select source file processing method": "选择源文件处理方法", "Select the model to be trained (Depending on the Tab page you are on)": "根据您所在的选项卡页面选择要训练的模型", "Selected: {}": "已选择: {}", "Speaker": "说话人", "Speaker is identified by the folder name": "自动根据父目录名称识别说话人", "Start Training": "开始训练", "Streaming Audio": "流式音频", "Streaming Generate": "流式合成", "Tensorboard Host": "Tensorboard 监听地址", "Tensorboard Log Path": "Tensorboard 日志路径", "Tensorboard Port": "Tensorboard 端口", "Tensorboard interface is closed": "Tensorboard 界面已关闭", "Tensorboard interface is launched at {}": "Tensorboard 界面已在 {} 上启动", "Text is too long, please keep it under {} characters.": "文本太长,请保持在 {} 个字符以内.", "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list.": "左侧输入文件夹的路径或文件列表。无论是否选中,都将在此列表中用于后续训练.", "Training Configuration": "训练配置", "Training Error": "训练错误", "Training stopped": "训练已停止", "Type name of the speaker": "输入说话人的名称", "Type the path or select from the dropdown": "输入路径或从下拉菜单中选择", "Use LoRA": "使用 LoRA", "Use LoRA can save GPU memory, but may reduce the quality of the model": "使用 LoRA 可以节省 GPU 内存,但可能会降低模型质量", "Use filelist": "使用文件列表", "Use large for 10G+ GPU, medium for 5G, small for 2G": "10G+ GPU 使用 large, 5G 使用 medium, 2G 使用 small", "VITS Configuration": "VITS 配置", "VQGAN Configuration": "VQGAN 配置", "Validation Batch Size": "验证批次大小", "View the status of the preprocessing folder (use the slider to control the depth of the tree)": "查看预处理文件夹的状态 (使用滑块控制树的深度)", "We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.": "我们不对模型的任何滥用负责,请在使用之前考虑您当地的法律法规.", "WebUI Host": "WebUI 监听地址", "WebUI Port": "WebUI 端口", "Whisper Model": "Whisper 模型", "You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1).": "你可以在 [这里](https://github.com/fishaudio/fish-speech) 找到源代码和 [这里](https://huggingface.co/fishaudio/fish-speech-1) 找到模型.", "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU": "30+ 系列 GPU 建议使用 bf16-true, 10+ 系列 GPU 建议使用 16-mixed", "latest": "最近的检查点", "new": "创建新的检查点", "Realtime Transform Text": "实时规范化文本", "Normalization Result Preview (Currently Only Chinese)": "规范化结果预览", "Text Normalization": "文本规范化"}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122import astimport globimport jsonfrom collections import OrderedDictfrom pathlib import Path
from loguru import logger
from .core import DEFAULT_LANGUAGE, I18N_FILE_PATH
def extract_i18n_strings(node): i18n_strings = []
if ( isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id == "i18n" ): for arg in node.args: if isinstance(arg, ast.Str): i18n_strings.append(arg.s)
for child_node in ast.iter_child_nodes(node): i18n_strings.extend(extract_i18n_strings(child_node))
return i18n_strings
# scan the directory for all .py files (recursively)# for each file, parse the code into an AST# for each AST, extract the i18n strings
strings = []folders = ["fish_speech", "tools"]# for filename in glob.iglob("**/*.py", recursive=True):for folder in folders: for f in Path(folder).rglob("*.py"): code = f.read_text(encoding="utf-8") if "i18n(" in code: tree = ast.parse(code) i18n_strings = extract_i18n_strings(tree) logger.info(f"Found {len(i18n_strings)} i18n strings in {f}") strings.extend(i18n_strings)
code_keys = set(strings)logger.info(f"Total unique: {len(code_keys)}")
standard_file = I18N_FILE_PATH / f"{DEFAULT_LANGUAGE}.json"with open(standard_file, "r", encoding="utf-8") as f: standard_data = json.load(f, object_pairs_hook=OrderedDict)standard_keys = set(standard_data.keys())
# Define the standard file nameunused_keys = standard_keys - code_keyslogger.info(f"Found {len(unused_keys)} unused keys in {standard_file}")for unused_key in unused_keys: logger.info(f"\t{unused_key}")
missing_keys = code_keys - standard_keyslogger.info(f"Found {len(missing_keys)} missing keys in {standard_file}")for missing_key in missing_keys: logger.info(f"\t{missing_key}")
code_keys_dict = OrderedDict()for s in strings: code_keys_dict[s] = s
# write backwith open(standard_file, "w", encoding="utf-8") as f: json.dump(code_keys_dict, f, ensure_ascii=False, indent=4, sort_keys=True) f.write("\n")
logger.info(f"Updated {standard_file}")
# Define the standard file namestandard_file = I18N_FILE_PATH / f"{DEFAULT_LANGUAGE}.json"
# Find all JSON files in the directorydir_path = I18N_FILE_PATHlanguages = [f for f in dir_path.glob("*.json") if f.stem != DEFAULT_LANGUAGE]
# Load the standard filewith open(standard_file, "r", encoding="utf-8") as f: standard_data = json.load(f, object_pairs_hook=OrderedDict)
# Loop through each language filefor lang_file in languages: # Load the language file with open(lang_file, "r", encoding="utf-8") as f: lang_data = json.load(f, object_pairs_hook=OrderedDict)
# Find the difference between the language file and the standard file diff = set(standard_data.keys()) - set(lang_data.keys())
miss = set(lang_data.keys()) - set(standard_data.keys())
# Add any missing keys to the language file for key in diff: lang_data[key] = "#!" + key logger.info(f"Added missing key: {key} to {lang_file}")
# Del any extra keys to the language file for key in miss: del lang_data[key] logger.info(f"Del extra key: {key} from {lang_file}")
# Sort the keys of the language file to match the order of the standard file lang_data = OrderedDict( sorted(lang_data.items(), key=lambda x: list(standard_data.keys()).index(x[0])) )
# Save the updated language file with open(lang_file, "w", encoding="utf-8") as f: json.dump(lang_data, f, ensure_ascii=False, indent=4, sort_keys=True) f.write("\n")
logger.info(f"Updated {lang_file}")
logger.info("Done")12345364 unmodified lines370371372373374375import jsonimport mathfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Optional364 unmodified linesweights = torch.load(Path(path) / "model.pth", map_location="cpu", mmap=True)err = model.load_state_dict(weights, strict=False, assign=True)log.info(f"Loaded weights with error: {err}")123456364 unmodified lines371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402import jsonimport mathfrom collections import OrderedDictfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Optional364 unmodified linesweights = torch.load(Path(path) / "model.pth", map_location="cpu", mmap=True)if "state_dict" in weights:logger.warning("Using a TextToSemantic LightningModule checkpoint, ""please make sure it is a full model, not a LoRA model.")weights = weights["state_dict"]if next(iter(weights.keys())).startswith("model."):logger.info(f"Remove prefix 'model.' created by TextToSemantic LightningModule from keys")new_weights = OrderedDict()for k, v in weights.items():new_weights[k.replace("model.", "")] = vweights = new_weights# Verify the name and shape of parameters since strict=False in load_state_dict.for k, v in model.named_parameters():if k not in weights:logger.warning(f"No weight for {k}")elif v.shape != weights[k].shape:logger.warning(f"Shape mismatch for {k}: {v.shape} vs {weights[k].shape}")err = model.load_state_dict(weights, strict=False, assign=True)log.info(f"Loaded weights with error: {err}")
123from .lit_module import VQGAN__all__ = ["VQGAN"]
123456789101112131415161718192021222324251 unmodified line2728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310414 unmodified lines11912012112212312412527 unmodified lines1531541551561571581594 unmodified lines164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247116 unmodified lines36436536636736836937037137237337446 unmodified lines42142242342442542642742842943043143258 unmodified lines49149249349449549631 unmodified lines5285295305315325335345355365375385395405415425435445455465475485495505515525 unmodified lines558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625# A inference only version of the FireflyGAN modelimport mathfrom functools import partialfrom math import prodfrom typing import Callableimport numpy as npimport torchimport torch.nn.functional as Ffrom torch import nnfrom torch.nn import Conv1dfrom torch.nn.utils.parametrizations import weight_normfrom torch.nn.utils.parametrize import remove_parametrizationsfrom torch.utils.checkpoint import checkpointfrom fish_speech.models.vqgan.utils import sequence_maskdef init_weights(m, mean=0.0, std=0.01):classname = m.__class__.__name__if classname.find("Conv") != -1:m.weight.data.normal_(mean, std)1 unmodified linereturn (kernel_size * dilation - dilation) // 2class ResBlock1(torch.nn.Module):def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):super().__init__()self.convs1 = nn.ModuleList([weight_norm(Conv1d(channels,channels,kernel_size,1,dilation=dilation[0],padding=get_padding(kernel_size, dilation[0]),)),weight_norm(Conv1d(channels,channels,kernel_size,1,dilation=dilation[1],padding=get_padding(kernel_size, dilation[1]),)),weight_norm(Conv1d(channels,channels,kernel_size,1,dilation=dilation[2],padding=get_padding(kernel_size, dilation[2]),)),])self.convs1.apply(init_weights)self.convs2 = nn.ModuleList([weight_norm(Conv1d(channels,channels,kernel_size,1,dilation=1,padding=get_padding(kernel_size, 1),)),weight_norm(Conv1d(channels,channels,kernel_size,1,dilation=1,padding=get_padding(kernel_size, 1),)),weight_norm(Conv1d(channels,channels,kernel_size,1,dilation=1,padding=get_padding(kernel_size, 1),)),])self.convs2.apply(init_weights)14 unmodified linesremove_parametrizations(conv, tensor_name="weight")class ParralelBlock(nn.Module):def __init__(self,channels: int,27 unmodified linesresblock_dilation_sizes: tuple[tuple[int]] = ((1, 3, 5), (1, 3, 5), (1, 3, 5)),num_mels: int = 128,upsample_initial_channel: int = 512,use_template: bool = True,pre_conv_kernel_size: int = 7,post_conv_kernel_size: int = 7,post_activation: Callable = partial(nn.SiLU, inplace=True),4 unmodified linesprod(upsample_rates) == hop_length), f"hop_length must be {prod(upsample_rates)}"self.conv_pre = weight_norm(nn.Conv1d(num_mels,upsample_initial_channel,pre_conv_kernel_size,1,padding=get_padding(pre_conv_kernel_size),))self.num_upsamples = len(upsample_rates)self.num_kernels = len(resblock_kernel_sizes)self.noise_convs = nn.ModuleList()self.use_template = use_templateself.ups = nn.ModuleList()for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):c_cur = upsample_initial_channel // (2 ** (i + 1))self.ups.append(weight_norm(nn.ConvTranspose1d(upsample_initial_channel // (2**i),upsample_initial_channel // (2 ** (i + 1)),k,u,padding=(k - u) // 2,)))if not use_template:continueif i + 1 < len(upsample_rates):stride_f0 = np.prod(upsample_rates[i + 1 :])self.noise_convs.append(Conv1d(1,c_cur,kernel_size=stride_f0 * 2,stride=stride_f0,padding=stride_f0 // 2,))else:self.noise_convs.append(Conv1d(1, c_cur, kernel_size=1))self.resblocks = nn.ModuleList()for i in range(len(self.ups)):ch = upsample_initial_channel // (2 ** (i + 1))self.resblocks.append(ParralelBlock(ch, resblock_kernel_sizes, resblock_dilation_sizes))self.activation_post = post_activation()self.conv_post = weight_norm(nn.Conv1d(ch,1,post_conv_kernel_size,1,padding=get_padding(post_conv_kernel_size),))self.ups.apply(init_weights)self.conv_post.apply(init_weights)def forward(self, x, template=None):x = self.conv_pre(x)for i in range(self.num_upsamples):x = F.silu(x, inplace=True)x = self.ups[i](x)if self.use_template:x = x + self.noise_convs[i](template)if self.training and self.checkpointing:x = checkpoint(self.resblocks[i],116 unmodified lines):super().__init__()self.dwconv = nn.Conv1d(dim,dim,kernel_size=kernel_size,padding=int(dilation * (kernel_size - 1) / 2),groups=dim,) # depthwise convself.norm = LayerNorm(dim, eps=1e-6)46 unmodified linesself.downsample_layers = nn.ModuleList()stem = nn.Sequential(nn.Conv1d(input_channels,dims[0],kernel_size=kernel_size,padding=kernel_size // 2,padding_mode="zeros",),LayerNorm(dims[0], eps=1e-6, data_format="channels_first"),)58 unmodified linesself.head = headself.quantizer = quantizerself.spec_transform = spec_transformdef forward(self, x: torch.Tensor, template=None, mask=None) -> torch.Tensor:if self.spec_transform is not None:31 unmodified lines# Encodeencoded_features = self.backbone(mels) * mel_masks_float_convfeature_lengths = mel_lengths // math.prod(self.quantizer.downsample_factor)return self.quantizer.encode(encoded_features), feature_lengthsdef decode(self, indices, feature_lengths) -> torch.Tensor:factor = math.prod(self.quantizer.downsample_factor)mel_masks = sequence_mask(feature_lengths * factor, indices.shape[2] * factor)mel_masks_float_conv = mel_masks[:, None, :].float()audio_masks = sequence_mask(feature_lengths * factor * self.spec_transform.hop_length,indices.shape[2] * factor * self.spec_transform.hop_length,)audio_masks_float_conv = audio_masks[:, None, :].float()z = self.quantizer.decode(indices) * mel_masks_float_convx = self.head(z) * audio_masks_float_convreturn xdef remove_parametrizations(self):if hasattr(self.backbone, "remove_parametrizations"):5 unmodified lines@propertydef device(self):return next(self.parameters()).deviceclass FireflyBase(nn.Module):def __init__(self, ckpt_path: str = None, pretrained: bool = True):super().__init__()self.backbone = ConvNeXtEncoder(input_channels=128,depths=[3, 3, 9, 3],dims=[128, 256, 384, 512],drop_path_rate=0.2,kernel_size=7,)self.head = HiFiGANGenerator(hop_length=512,upsample_rates=[8, 8, 2, 2, 2],upsample_kernel_sizes=[16, 16, 4, 4, 4],resblock_kernel_sizes=[3, 7, 11],resblock_dilation_sizes=[[1, 3, 5], [1, 3, 5], [1, 3, 5]],num_mels=512,upsample_initial_channel=512,use_template=False,pre_conv_kernel_size=13,post_conv_kernel_size=13,)if ckpt_path is not None:state_dict = torch.load(ckpt_path, map_location="cpu")elif pretrained:state_dict = torch.hub.load_state_dict_from_url("https://github.com/fishaudio/vocoder/releases/download/1.0.0/firefly-gan-base-generator.ckpt",map_location="cpu",model_dir="checkpoints",)if "state_dict" in state_dict:state_dict = state_dict["state_dict"]if any("generator." in k for k in state_dict):state_dict = {k.replace("generator.", ""): vfor k, v in state_dict.items()if "generator." in k}self.load_state_dict(state_dict, strict=True)self.head.remove_parametrizations()@torch.no_grad()def forward(self, x: torch.Tensor) -> torch.Tensor:x = self.backbone(x)x = self.head(x)if x.ndim == 2:x = x[:, None, :]return xif __name__ == "__main__":model = FireflyBase()model.eval()x = torch.randn(1, 128, 128)with torch.no_grad():y = model(x)print(y.shape)12345678910111213141516171819202122232425261 unmodified line28293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716814 unmodified lines18318418518618718818927 unmodified lines2172182192202212224 unmodified lines227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276116 unmodified lines39339439539639739839940040140240346 unmodified lines45045145245345445545645745845946046146258 unmodified lines52152252352452552652731 unmodified lines5595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885 unmodified lines594595596import mathfrom functools import partialfrom math import prodfrom typing import Callableimport torchimport torch.nn.functional as Ffrom torch import nnfrom torch.nn.utils.parametrizations import weight_normfrom torch.nn.utils.parametrize import remove_parametrizationsfrom torch.utils.checkpoint import checkpointdef sequence_mask(length, max_length=None):if max_length is None:max_length = length.max()x = torch.arange(max_length, dtype=length.dtype, device=length.device)return x.unsqueeze(0) < length.unsqueeze(1)def init_weights(m, mean=0.0, std=0.01):classname = m.__class__.__name__if classname.find("Conv1D") != -1:m.weight.data.normal_(mean, std)1 unmodified linereturn (kernel_size * dilation - dilation) // 2def unpad1d(x: torch.Tensor, paddings: tuple[int, int]):"""Remove padding from x, handling properly zero padding. Only for 1d!"""padding_left, padding_right = paddingsassert padding_left >= 0 and padding_right >= 0, (padding_left, padding_right)assert (padding_left + padding_right) <= x.shape[-1]end = x.shape[-1] - padding_rightreturn x[..., padding_left:end]def get_extra_padding_for_conv1d(x: torch.Tensor, kernel_size: int, stride: int, padding_total: int = 0) -> int:"""See `pad_for_conv1d`."""length = x.shape[-1]n_frames = (length - kernel_size + padding_total) / stride + 1ideal_length = (math.ceil(n_frames) - 1) * stride + (kernel_size - padding_total)return ideal_length - lengthdef pad1d(x: torch.Tensor,paddings: tuple[int, int],mode: str = "zeros",value: float = 0.0,):"""Tiny wrapper around F.pad, just to allow for reflect padding on small input.If this is the case, we insert extra 0 padding to the rightbefore the reflection happen."""length = x.shape[-1]padding_left, padding_right = paddingsassert padding_left >= 0 and padding_right >= 0, (padding_left, padding_right)if mode == "reflect":max_pad = max(padding_left, padding_right)extra_pad = 0if length <= max_pad:extra_pad = max_pad - length + 1x = F.pad(x, (0, extra_pad))padded = F.pad(x, paddings, mode, value)end = padded.shape[-1] - extra_padreturn padded[..., :end]else:return F.pad(x, paddings, mode, value)class FishConvNet(nn.Module):def __init__(self, in_channels, out_channels, kernel_size, dilation=1, stride=1, groups=1):super(FishConvNet, self).__init__()self.conv = nn.Conv1d(in_channels,out_channels,kernel_size,stride=stride,dilation=dilation,groups=groups,)self.stride = strideself.kernel_size = (kernel_size - 1) * dilation + 1self.dilation = dilationdef forward(self, x):pad = self.kernel_size - self.strideextra_padding = get_extra_padding_for_conv1d(x, self.kernel_size, self.stride, pad)x = pad1d(x, (pad, extra_padding), mode="constant", value=0)return self.conv(x).contiguous()def weight_norm(self, name="weight", dim=0):self.conv = weight_norm(self.conv, name=name, dim=dim)return selfdef remove_weight_norm(self):self.conv = remove_parametrizations(self.conv)return selfclass FishTransConvNet(nn.Module):def __init__(self, in_channels, out_channels, kernel_size, dilation=1, stride=1):super(FishTransConvNet, self).__init__()self.conv = nn.ConvTranspose1d(in_channels, out_channels, kernel_size, stride=stride, dilation=dilation)self.stride = strideself.kernel_size = kernel_sizedef forward(self, x):x = self.conv(x)pad = self.kernel_size - self.stridepadding_right = math.ceil(pad)padding_left = pad - padding_rightx = unpad1d(x, (padding_left, padding_right))return x.contiguous()def weight_norm(self, name="weight", dim=0):self.conv = weight_norm(self.conv, name=name, dim=dim)return selfdef remove_weight_norm(self):self.conv = remove_parametrizations(self.conv)return selfclass ResBlock1(torch.nn.Module):def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):super().__init__()self.convs1 = nn.ModuleList([FishConvNet(channels, channels, kernel_size, stride=1, dilation=dilation[0]).weight_norm(),FishConvNet(channels, channels, kernel_size, stride=1, dilation=dilation[1]).weight_norm(),FishConvNet(channels, channels, kernel_size, stride=1, dilation=dilation[2]).weight_norm(),])self.convs1.apply(init_weights)self.convs2 = nn.ModuleList([FishConvNet(channels, channels, kernel_size, stride=1, dilation=dilation[0]).weight_norm(),FishConvNet(channels, channels, kernel_size, stride=1, dilation=dilation[1]).weight_norm(),FishConvNet(channels, channels, kernel_size, stride=1, dilation=dilation[2]).weight_norm(),])self.convs2.apply(init_weights)14 unmodified linesremove_parametrizations(conv, tensor_name="weight")class ParallelBlock(nn.Module):def __init__(self,channels: int,27 unmodified linesresblock_dilation_sizes: tuple[tuple[int]] = ((1, 3, 5), (1, 3, 5), (1, 3, 5)),num_mels: int = 128,upsample_initial_channel: int = 512,pre_conv_kernel_size: int = 7,post_conv_kernel_size: int = 7,post_activation: Callable = partial(nn.SiLU, inplace=True),4 unmodified linesprod(upsample_rates) == hop_length), f"hop_length must be {prod(upsample_rates)}"self.conv_pre = FishConvNet(num_mels,upsample_initial_channel,pre_conv_kernel_size,stride=1,).weight_norm()self.num_upsamples = len(upsample_rates)self.num_kernels = len(resblock_kernel_sizes)self.noise_convs = nn.ModuleList()self.ups = nn.ModuleList()for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):self.ups.append(FishTransConvNet(upsample_initial_channel // (2**i),upsample_initial_channel // (2 ** (i + 1)),k,stride=u,).weight_norm())self.resblocks = nn.ModuleList()for i in range(len(self.ups)):ch = upsample_initial_channel // (2 ** (i + 1))self.resblocks.append(ParallelBlock(ch, resblock_kernel_sizes, resblock_dilation_sizes))self.activation_post = post_activation()self.conv_post = FishConvNet(ch, 1, post_conv_kernel_size, stride=1).weight_norm()self.ups.apply(init_weights)self.conv_post.apply(init_weights)def forward(self, x):x = self.conv_pre(x)for i in range(self.num_upsamples):x = F.silu(x, inplace=True)x = self.ups[i](x)if self.training and self.checkpointing:x = checkpoint(self.resblocks[i],116 unmodified lines):super().__init__()self.dwconv = FishConvNet(dim,dim,kernel_size=kernel_size,# padding=int(dilation * (kernel_size - 1) / 2),groups=dim,) # depthwise convself.norm = LayerNorm(dim, eps=1e-6)46 unmodified linesself.downsample_layers = nn.ModuleList()stem = nn.Sequential(FishConvNet(input_channels,dims[0],kernel_size=7,# padding=3,# padding_mode="replicate",# padding_mode="zeros",),LayerNorm(dims[0], eps=1e-6, data_format="channels_first"),)58 unmodified linesself.head = headself.quantizer = quantizerself.spec_transform = spec_transformself.downsample_factor = math.prod(self.quantizer.downsample_factor)def forward(self, x: torch.Tensor, template=None, mask=None) -> torch.Tensor:if self.spec_transform is not None:31 unmodified lines# Encodeencoded_features = self.backbone(mels) * mel_masks_float_convfeature_lengths = mel_lengths // self.downsample_factorreturn self.quantizer.encode(encoded_features), feature_lengthsdef decode(self, indices, feature_lengths) -> torch.Tensor:mel_masks = sequence_mask(feature_lengths * self.downsample_factor,indices.shape[2] * self.downsample_factor,)mel_masks_float_conv = mel_masks[:, None, :].float()audio_lengths = (feature_lengths * self.downsample_factor * self.spec_transform.hop_length)audio_masks = sequence_mask(audio_lengths,indices.shape[2] * self.downsample_factor * self.spec_transform.hop_length,)audio_masks_float_conv = audio_masks[:, None, :].float()z = self.quantizer.decode(indices) * mel_masks_float_convx = self.head(z) * audio_masks_float_convreturn x, audio_lengthsdef remove_parametrizations(self):if hasattr(self.backbone, "remove_parametrizations"):5 unmodified lines@propertydef device(self):return next(self.parameters()).device
5 unmodified lines67891011127 unmodified lines2021222324252619 unmodified lines464748495051528 unmodified lines6162636465666746 unmodified lines1141151161171181191201211221231241251261271281291301311321331341351361371381395 unmodified linesfrom einops import rearrangefrom vector_quantize_pytorch import GroupedResidualFSQfrom .firefly import ConvNeXtBlock@dataclass7 unmodified linesdef __init__(self,input_dim: int = 512,n_codebooks: int = 1,n_groups: int = 1,levels: tuple[int] = (8, 5, 5, 5), # Approximate 2**10downsample_factor: tuple[int] = (2, 2),19 unmodified linesself.downsample = nn.Sequential(*[nn.Sequential(nn.Conv1d(all_dims[idx],all_dims[idx + 1],kernel_size=factor,8 unmodified linesself.upsample = nn.Sequential(*[nn.Sequential(nn.ConvTranspose1d(all_dims[idx + 1],all_dims[idx],kernel_size=factor,46 unmodified linesz_q = self.residual_fsq.get_output_from_indices(indices)z_q = self.upsample(z_q.mT)return z_q# def from_latents(self, latents: torch.Tensor):# z_q, z_p, codes = super().from_latents(latents)# z_q = self.upsample(z_q)# return z_q, z_p, codesif __name__ == "__main__":rvq = DownsampleFiniteScalarQuantize(n_codebooks=1,downsample_factor=(2, 2),)x = torch.randn(16, 512, 80)result = rvq(x)print(rvq)print(result.latents.shape, result.codes.shape, result.z.shape)# y = rvq.from_codes(result.codes)# print(y[0].shape)# y = rvq.from_latents(result.latents)# print(y[0].shape)5 unmodified lines67891011127 unmodified lines2021222324252619 unmodified lines464748495051528 unmodified lines6162636465666746 unmodified lines1141151165 unmodified linesfrom einops import rearrangefrom vector_quantize_pytorch import GroupedResidualFSQfrom .firefly import ConvNeXtBlock, FishConvNet, FishTransConvNet@dataclass7 unmodified linesdef __init__(self,input_dim: int = 512,n_codebooks: int = 9,n_groups: int = 1,levels: tuple[int] = (8, 5, 5, 5), # Approximate 2**10downsample_factor: tuple[int] = (2, 2),19 unmodified linesself.downsample = nn.Sequential(*[nn.Sequential(FishConvNet(all_dims[idx],all_dims[idx + 1],kernel_size=factor,8 unmodified linesself.upsample = nn.Sequential(*[nn.Sequential(FishTransConvNet(all_dims[idx + 1],all_dims[idx],kernel_size=factor,46 unmodified linesz_q = self.residual_fsq.get_output_from_indices(indices)z_q = self.upsample(z_q.mT)return z_q
3 unmodified lines45678910111213145 unmodified lines2021223 unmodified linesdef get_cosine_schedule_with_warmup_lr_lambda(current_step: int,*,num_warmup_steps: int,num_training_steps: int,num_cycles: float = 0.5,final_lr_ratio: float = 0.0,):if current_step < num_warmup_steps:return float(current_step) / float(max(1, num_warmup_steps))5 unmodified linesfinal_lr_ratio,0.5 * (1.0 + math.cos(math.pi * float(num_cycles) * 2.0 * progress)),)3 unmodified lines45678910111213141516175 unmodified lines2324252627282930313233343536373839403 unmodified linesdef get_cosine_schedule_with_warmup_lr_lambda(current_step: int,*,num_warmup_steps: int | float,num_training_steps: int,num_cycles: float = 0.5,final_lr_ratio: float = 0.0,):if 0 < num_warmup_steps < 1: # float modenum_warmup_steps = int(num_warmup_steps * num_training_steps)if current_step < num_warmup_steps:return float(current_step) / float(max(1, num_warmup_steps))5 unmodified linesfinal_lr_ratio,0.5 * (1.0 + math.cos(math.pi * float(num_cycles) * 2.0 * progress)),)def get_constant_schedule_with_warmup_lr_lambda(current_step: int,*,num_warmup_steps: int | float,num_training_steps: int | None = None,):if 0 < num_warmup_steps < 1: # float modenum_warmup_steps = int(num_warmup_steps * num_training_steps)if current_step < num_warmup_steps:return float(current_step) / float(max(1, num_warmup_steps))return 1.0
63 unmodified lines64656667686963 unmodified lines# Replace all chinese symbols with their english counterpartstext = REPLACE_SYMBOL_REGEX.sub(lambda x: SYMBOLS_MAPPING[x.group()], text)text = REMOVE_UNKNOWN_SYMBOL_REGEX.sub("", text)return text63 unmodified lines64656667686963 unmodified lines# Replace all chinese symbols with their english counterpartstext = REPLACE_SYMBOL_REGEX.sub(lambda x: SYMBOLS_MAPPING[x.group()], text)# text = REMOVE_UNKNOWN_SYMBOL_REGEX.sub("", text)return text
12342 unmodified lines78910111248 unmodified lines61626364656667import osfrom typing import Optionalimport hydra2 unmodified linesimport torchfrom lightning import Callback, LightningDataModule, LightningModule, Trainerfrom lightning.pytorch.loggers import Loggerfrom omegaconf import DictConfig, OmegaConfos.environ.pop("SLURM_NTASKS", None)48 unmodified lineslog.info(f"Instantiating trainer <{cfg.trainer._target_}>")trainer: Trainer = hydra.utils.instantiate(cfg.trainer, callbacks=callbacks, logger=logger)object_dict = {123452 unmodified lines89101112131448 unmodified lines636465666768697071import osimport sysfrom typing import Optionalimport hydra2 unmodified linesimport torchfrom lightning import Callback, LightningDataModule, LightningModule, Trainerfrom lightning.pytorch.loggers import Loggerfrom lightning.pytorch.strategies import DDPStrategyfrom omegaconf import DictConfig, OmegaConfos.environ.pop("SLURM_NTASKS", None)48 unmodified lineslog.info(f"Instantiating trainer <{cfg.trainer._target_}>")trainer: Trainer = hydra.utils.instantiate(cfg.trainer,callbacks=callbacks,logger=logger,)object_dict = {
123413 unmodified lines18192021from .braceexpand import braceexpandfrom .file import get_latest_checkpointfrom .instantiators import instantiate_callbacks, instantiate_loggersfrom .logger import RankedLogger13 unmodified lines"task_wrapper","braceexpand","get_latest_checkpoint",]1234513 unmodified lines1920212223from .braceexpand import braceexpandfrom .context import autocast_exclude_mpsfrom .file import get_latest_checkpointfrom .instantiators import instantiate_callbacks, instantiate_loggersfrom .logger import RankedLogger13 unmodified lines"task_wrapper","braceexpand","get_latest_checkpoint","autocast_exclude_mps",]
12345678910111213from contextlib import nullcontext
import torch
def autocast_exclude_mps( device_type: str, dtype: torch.dtype) -> nullcontext | torch.autocast: return ( nullcontext() if torch.backends.mps.is_available() else torch.autocast(device_type, dtype) )123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354558 unmodified lines646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119import osfrom glob import globfrom pathlib import Pathfrom typing import Unionfrom loguru import loggerfrom natsort import natsortedAUDIO_EXTENSIONS = {".mp3",".wav",".flac",".ogg",".m4a",".wma",".aac",".aiff",".aif",".aifc",}def list_files(path: Union[Path, str],extensions: set[str] = None,recursive: bool = False,sort: bool = True,) -> list[Path]:"""List files in a directory.Args:path (Path): Path to the directory.extensions (set, optional): Extensions to filter. Defaults to None.recursive (bool, optional): Whether to search recursively. Defaults to False.sort (bool, optional): Whether to sort the files. Defaults to True.Returns:list: List of files."""if isinstance(path, str):path = Path(path)if not path.exists():raise FileNotFoundError(f"Directory {path} does not exist.")files = [file for ext in extensions for file in path.rglob(f"*{ext}")]if sort:files = natsorted(files)return filesdef get_latest_checkpoint(path: Path | str) -> Path | None:8 unmodified linesreturn Nonereturn ckpts[-1]def load_filelist(path: Path | str) -> list[tuple[Path, str, str, str]]:"""Load a Bert-VITS2 style filelist."""files = set()results = []count_duplicated, count_not_found = 0, 0LANGUAGE_TO_LANGUAGES = {"zh": ["zh", "en"],"jp": ["jp", "en"],"en": ["en"],}with open(path, "r", encoding="utf-8") as f:for line in f.readlines():splits = line.strip().split("|", maxsplit=3)if len(splits) != 4:logger.warning(f"Invalid line: {line}")continuefilename, speaker, language, text = splitsfile = Path(filename)language = language.strip().lower()if language == "ja":language = "jp"assert language in ["zh", "jp", "en"], f"Invalid language {language}"languages = LANGUAGE_TO_LANGUAGES[language]if file in files:logger.warning(f"Duplicated file: {file}")count_duplicated += 1continueif not file.exists():logger.warning(f"File not found: {file}")count_not_found += 1continueresults.append((file, speaker, languages, text))if count_duplicated > 0:logger.warning(f"Total duplicated files: {count_duplicated}")if count_not_found > 0:logger.warning(f"Total files not found: {count_not_found}")return results123458 unmodified lines141516import osfrom pathlib import Pathdef get_latest_checkpoint(path: Path | str) -> Path | None:8 unmodified linesreturn Nonereturn ckpts[-1]
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161:root { --my-200: #80eeee; --my-50: #ecfdf5; --water-width: 300px; --water-heigh: 300px;}
/* general styled components */.tools { align-items: center; justify-content: center;}
.gradio-button { max-width: 2.2em; min-width: 2.2em !important; height: 2.4em; align-self: end; line-height: 1em; border-radius: 0.5em;
}
.gradio-button.secondary-down, .gradio-button.secondary-down:hover{ box-shadow: 1px 1px 1px rgba(0,0,0,0.25) inset, 0px 0px 3px rgba(0,0,0,0.15) inset;}
/* replace original footer with ours */a{ font-weight: bold; cursor: pointer; color: #030C14 !important;}
footer { display: none !important;}
#footer{ text-align: center;}
#footer div{ display: inline-block;}
#footer .versions{ font-size: 85%; opacity: 0.85;}
/*@keyframes moveBackground {*//* 0% {*//* background-position: 0 0;*//* }*//* 100% {*//* background-position: -100px 100px;*//* }*//*}*/@keyframes moveJellyBackground { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; }}
.gradio-container { position: absolute; z-index: 10;}
.quan { position: absolute; bottom: 0; width: var(--water-width); height: var(--water-heigh); border-radius: 0; /*border: 3px solid rgb(246, 247, 248);*/ /*box-shadow: 0 0 0 3px rgb(41, 134, 196);*/ z-index: 0;
}
.quan:last-child { margin-right: 0;}
.shui { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgb(23, 106, 201); border-radius: 0; overflow: hidden; z-index: 0;}
.shui::after {
content: ''; position: absolute; top: 20%; left: 50%; width: 150%; height: 150%; border-radius: 40%; background-image: radial-gradient(circle at 0% 50%, #dcfcf1, var(--my-50) 50%); animation: shi 5s linear infinite;}
@keyframes shi { 0% { transform: translate(-50%, -65%) rotate(0deg); } 100% { transform: translate(-50%, -65%) rotate(360deg); }}
.shui::before { content: ''; position: absolute; top: 20%; left: 50%; width: 150%; height: 150%; border-radius: 42%; background-color: rgb(240, 228, 228, 0.2); animation: xu 7s linear infinite;}
@keyframes xu { 0% { transform: translate(-50%, -60%) rotate(0deg); } 100% { transform: translate(-50%, -60%) rotate(360deg); }}
fieldset.data_src div.wrap label { background: #f8bffee0 !important;}
.scrollable-component { max-height: 100px; overflow-y: auto;}
#file_accordion { max-height: 220px !important;}1234567891011<div style="color: rgba(25,255,205,0.7) !important;"> <a href="{api_docs}">API</a> • <a href="https://github.com/fishaudio/fish-speech">Github</a> • <a href="https://gradio.app">Gradio</a></div><br /><div class="versions" style="color: rgba(25,255,205,0.7) !important;">{versions}</div>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
function createGradioAnimation() { const params = new URLSearchParams(window.location.search); if (!params.has('__theme')) { params.set('__theme', 'light'); window.location.search = params.toString(); }
var gradioApp = document.querySelector('gradio-app'); if (gradioApp) {
document.documentElement.style.setProperty('--my-200', '#80eeee'); document.documentElement.style.setProperty('--my-50', '#ecfdf5');
// gradioApp.style.position = 'relative'; // gradioApp.style.backgroundSize = '200% 200%'; // gradioApp.style.animation = 'moveJellyBackground 10s ease infinite'; // gradioApp.style.backgroundImage = 'radial-gradient(circle at 0% 50%, var(--my-200), var(--my-50) 50%)'; // gradioApp.style.display = 'flex'; // gradioApp.style.justifyContent = 'flex-start'; // gradioApp.style.flexWrap = 'nowrap'; // gradioApp.style.overflowX = 'auto';
// for (let i = 0; i < 6; i++) { // var quan = document.createElement('div'); // quan.className = 'quan'; // gradioApp.insertBefore(quan, gradioApp.firstChild); // quan.id = 'quan' + i.toString(); // quan.style.left = 'calc(var(--water-width) * ' + i.toString() + ')'; // var quanContainer = document.querySelector('.quan'); // if (quanContainer) { // var shui = document.createElement('div'); // shui.className = 'shui'; // quanContainer.insertBefore(shui, quanContainer.firstChild) // } // } }
var container = document.createElement('div'); container.id = 'gradio-animation'; container.style.fontSize = '2em'; container.style.fontFamily = 'Maiandra GD, ui-monospace, monospace'; container.style.fontWeight = 'bold'; container.style.textAlign = 'center'; container.style.marginBottom = '20px';
var text = 'Welcome to Fish-Speech!'; for (var i = 0; i < text.length; i++) { (function(i){ setTimeout(function(){ var letter = document.createElement('span'); letter.style.opacity = '0'; letter.style.transition = 'opacity 0.5s'; letter.innerText = text[i];
container.appendChild(letter);
setTimeout(function() { letter.style.opacity = '1'; }, 50); }, i * 200); })(i); }
var gradioContainer = document.querySelector('.gradio-container'); gradioContainer.insertBefore(container, gradioContainer.firstChild);
return 'Animation created';}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120import importlib.utilimport osimport subprocessimport sysfrom functools import lru_cachefrom pathlib import Pathfrom typing import Iterable
import gradio as grfrom gradio.themes.base import Basefrom gradio.themes.utils import colors, fonts, sizes
GIT = ( (Path(os.environ.get("GIT_HOME", "")) / "git").resolve() if sys.platform == "win32" else "git")GIT = str(GIT)
def is_module_installed(module_name: str) -> bool: spec = importlib.util.find_spec(module_name) return spec is not None
@lru_cache()def commit_hash(): try: return subprocess.check_output( [GIT, "log", "-1", "--format='%h %s'"], shell=False, encoding="utf8" ).strip() except Exception: return "<none>"
def versions_html(): import torch
python_version = ".".join([str(x) for x in sys.version_info[0:3]]) commit = commit_hash() hash = commit.strip("'").split(" ")[0]
return f"""version: <a href="https://github.com/fishaudio/fish-speech/commit/{hash}">{hash}</a> • python: <span title="{sys.version}">{python_version}</span> • torch: {getattr(torch, '__long_version__',torch.__version__)} • gradio: {gr.__version__} • author: <a href="https://github.com/fishaudio">fishaudio</a>"""
def version_check(commit): try: import requests
commits = requests.get( "https://api.github.com/repos/fishaudio/fish-speech/branches/main" ).json() if commit != "<none>" and commits["commit"]["sha"] != commit: print("--------------------------------------------------------") print("| You are not up to date with the most recent release. |") print("| Consider running `git pull` to update. |") print("--------------------------------------------------------") elif commits["commit"]["sha"] == commit: print("You are up to date with the most recent release.") else: print("Not a git clone, can't perform version check.") except Exception as e: print("version check failed", e)
class Seafoam(Base): def __init__( self, *, primary_hue: colors.Color | str = colors.emerald, secondary_hue: colors.Color | str = colors.blue, neutral_hue: colors.Color | str = colors.blue, spacing_size: sizes.Size | str = sizes.spacing_md, radius_size: sizes.Size | str = sizes.radius_md, text_size: sizes.Size | str = sizes.text_lg, font: fonts.Font | str | Iterable[fonts.Font | str] = ( fonts.GoogleFont("Quicksand"), "ui-sans-serif", "sans-serif", ), font_mono: fonts.Font | str | Iterable[fonts.Font | str] = ( fonts.GoogleFont("IBM Plex Mono"), "ui-monospace", "monospace", ), ): super().__init__( primary_hue=primary_hue, secondary_hue=secondary_hue, neutral_hue=neutral_hue, spacing_size=spacing_size, radius_size=radius_size, text_size=text_size, font=font, font_mono=font_mono, ) super().set( button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)", button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)", button_primary_text_color="white", button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)", slider_color="*secondary_300", slider_color_dark="*secondary_600", block_title_text_weight="600", block_border_width="3px", block_shadow="*shadow_drop_lg", button_shadow="*shadow_drop_lg", button_small_padding="0px", button_large_padding="3px", )1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237from __future__ import annotations
import datetimeimport htmlimport jsonimport osimport platformimport shutilimport signalimport subprocessimport sysfrom pathlib import Path
import gradio as grimport psutilimport yamlfrom loguru import loggerfrom tqdm import tqdm
PYTHON = os.path.join(os.environ.get("PYTHON_FOLDERPATH", ""), "python")sys.path.insert(0, "")print(sys.path)cur_work_dir = Path(os.getcwd()).resolve()print("You are in ", str(cur_work_dir))
from fish_speech.i18n import i18nfrom fish_speech.webui.launch_utils import Seafoam, is_module_installed, versions_html
config_path = cur_work_dir / "fish_speech" / "configs"vqgan_yml_path = config_path / "firefly_gan_vq.yaml"llama_yml_path = config_path / "text2semantic_finetune.yaml"
env = os.environ.copy()env["no_proxy"] = "127.0.0.1, localhost, 0.0.0.0"
seafoam = Seafoam()
def build_html_error_message(error): return f""" <div style="color: red; font-weight: bold;"> {html.escape(error)} </div> """
def build_html_ok_message(msg): return f""" <div style="color: green; font-weight: bold;"> {html.escape(msg)} </div> """
def build_html_href(link, desc, msg): return f""" <span style="color: green; font-weight: bold; display: inline-block"> {html.escape(msg)} <a href="{link}">{desc}</a> </span> """
def load_data_in_raw(path): with open(path, "r", encoding="utf-8") as file: data = file.read() return str(data)
def kill_proc_tree(pid, including_parent=True): try: parent = psutil.Process(pid) except psutil.NoSuchProcess: # Process already terminated return
children = parent.children(recursive=True) for child in children: try: os.kill(child.pid, signal.SIGTERM) # or signal.SIGKILL except OSError: pass if including_parent: try: os.kill(parent.pid, signal.SIGTERM) # or signal.SIGKILL except OSError: pass
system = platform.system()p_label = Nonep_infer = Nonep_tensorboard = None
def kill_process(pid): if system == "Windows": cmd = "taskkill /t /f /pid %s" % pid # os.system(cmd) subprocess.run(cmd) else: kill_proc_tree(pid)
def change_label(if_label): global p_label if if_label == True and p_label is None: url = "http://localhost:3000" remote_url = "https://text-labeler.pages.dev/" try: p_label = subprocess.Popen( [ ( "asr-label-linux-x64" if sys.platform == "linux" else "asr-label-win-x64.exe" ) ] ) except FileNotFoundError: logger.warning("asr-label execution not found!")
yield build_html_href( link=remote_url, desc=i18n("Optional online ver"), msg=i18n("Opened labeler in browser"), )
elif if_label == False and p_label is not None: kill_process(p_label.pid) p_label = None yield build_html_ok_message("Nothing")
def clean_infer_cache(): import tempfile
temp_dir = Path(tempfile.gettempdir()) gradio_dir = str(temp_dir / "gradio") try: shutil.rmtree(gradio_dir) logger.info(f"Deleted cached audios: {gradio_dir}") except PermissionError: logger.info(f"Permission denied: Unable to delete {gradio_dir}") except FileNotFoundError: logger.info(f"{gradio_dir} was not found") except Exception as e: logger.info(f"An error occurred: {e}")
def change_infer( if_infer, host, port, infer_decoder_model, infer_decoder_config, infer_llama_model, infer_compile,): global p_infer if if_infer == True and p_infer == None: env = os.environ.copy()
env["GRADIO_SERVER_NAME"] = host env["GRADIO_SERVER_PORT"] = port # 启动第二个进程 url = f"http://{host}:{port}" yield build_html_ok_message( i18n("Inferring interface is launched at {}").format(url) )
clean_infer_cache()
p_infer = subprocess.Popen( [ PYTHON, "tools/webui.py", "--decoder-checkpoint-path", infer_decoder_model, "--decoder-config-name", infer_decoder_config, "--llama-checkpoint-path", infer_llama_model, ] + (["--compile"] if infer_compile == "Yes" else []), env=env, )
elif if_infer == False and p_infer is not None: kill_process(p_infer.pid) p_infer = None yield build_html_error_message(i18n("Infer interface is closed"))
js = load_data_in_raw("fish_speech/webui/js/animate.js")css = load_data_in_raw("fish_speech/webui/css/style.css")
data_pre_output = (cur_work_dir / "data").resolve()default_model_output = (cur_work_dir / "results").resolve()default_filelist = data_pre_output / "detect.list"data_pre_output.mkdir(parents=True, exist_ok=True)
items = []dict_items = {}
def load_yaml_data_in_fact(yml_path): with open(yml_path, "r", encoding="utf-8") as file: yml = yaml.safe_load(file) return yml
def write_yaml_data_in_fact(yml, yml_path): with open(yml_path, "w", encoding="utf-8") as file: yaml.safe_dump(yml, file, allow_unicode=True) return yml
def generate_tree(directory, depth=0, max_depth=None, prefix=""): if max_depth is not None and depth > max_depth: return ""
tree_str = "" files = [] directories = [] for item in os.listdir(directory): if os.path.isdir(os.path.join(directory, item)): directories.append(item) else: files.append(item)
entries = directories + files for i, entry in enumerate(entries): connector = "├── " if i < len(entries) - 1 else "└── " tree_str += f"{prefix}{connector}{entry}<br />" if i < len(directories): extension = "│ " if i < len(entries) - 1 else " " tree_str += generate_tree( os.path.join(directory, entry), depth + 1, max_depth, prefix=prefix + extension, ) return tree_str
def new_explorer(data_path, max_depth): return gr.Markdown( elem_classes=["scrollable-component"], value=generate_tree(data_path, max_depth=max_depth), )
def add_item( folder: str, method: str, label_lang: str, if_initial_prompt: bool, initial_prompt: str | None,): folder = folder.strip(" ").strip('"')
folder_path = Path(folder)
if folder and folder not in items and data_pre_output not in folder_path.parents: if folder_path.is_dir(): items.append(folder) dict_items[folder] = dict( type="folder", method=method, label_lang=label_lang, initial_prompt=initial_prompt if if_initial_prompt else None, ) elif folder: err = folder return gr.Checkboxgroup(choices=items), build_html_error_message( i18n("Invalid path: {}").format(err) )
formatted_data = json.dumps(dict_items, ensure_ascii=False, indent=4) logger.info("After Adding: " + formatted_data) gr.Info(formatted_data) return gr.Checkboxgroup(choices=items), build_html_ok_message( i18n("Added path successfully!") )
def remove_items(selected_items): global items, dict_items to_remove = [item for item in items if item in selected_items] for item in to_remove: del dict_items[item] items = [item for item in items if item in dict_items.keys()] formatted_data = json.dumps(dict_items, ensure_ascii=False, indent=4) logger.info(formatted_data) gr.Warning("After Removing: " + formatted_data) return gr.Checkboxgroup(choices=items, value=[]), build_html_ok_message( i18n("Removed path successfully!") )
def show_selected(options): selected_options = ", ".join(options)
if options: return i18n("Selected: {}").format(selected_options) else: return i18n("No selected options")
from pydub import AudioSegment
def convert_to_mono_in_place(audio_path: Path): audio = AudioSegment.from_file(audio_path) if audio.channels > 1: mono_audio = audio.set_channels(1) mono_audio.export(audio_path, format=audio_path.suffix[1:]) logger.info(f"Convert {audio_path} successfully")
def list_copy(list_file_path, method): wav_root = data_pre_output lst = [] with list_file_path.open("r", encoding="utf-8") as file: for line in tqdm(file, desc="Processing audio/transcript"): wav_path, speaker_name, language, text = line.strip().split("|") original_wav_path = Path(wav_path) target_wav_path = ( wav_root / original_wav_path.parent.name / original_wav_path.name ) lst.append(f"{target_wav_path}|{speaker_name}|{language}|{text}") if target_wav_path.is_file(): continue target_wav_path.parent.mkdir(parents=True, exist_ok=True) if method == i18n("Copy"): shutil.copy(original_wav_path, target_wav_path) else: shutil.move(original_wav_path, target_wav_path.parent) convert_to_mono_in_place(target_wav_path) original_lab_path = original_wav_path.with_suffix(".lab") target_lab_path = ( wav_root / original_wav_path.parent.name / original_wav_path.with_suffix(".lab").name ) if target_lab_path.is_file(): continue if method == i18n("Copy"): shutil.copy(original_lab_path, target_lab_path) else: shutil.move(original_lab_path, target_lab_path.parent)
if method == i18n("Move"): with list_file_path.open("w", encoding="utf-8") as file: file.writelines("\n".join(lst))
del lst return build_html_ok_message(i18n("Use filelist"))
def check_files(data_path: str, max_depth: int, label_model: str, label_device: str): global dict_items data_path = Path(data_path) gr.Warning("Pre-processing begins...") for item, content in dict_items.items(): item_path = Path(item) tar_path = data_path / item_path.name
if content["type"] == "folder" and item_path.is_dir(): if content["method"] == i18n("Copy"): os.makedirs(tar_path, exist_ok=True) shutil.copytree( src=str(item_path), dst=str(tar_path), dirs_exist_ok=True ) elif not tar_path.is_dir(): shutil.move(src=str(item_path), dst=str(tar_path))
for suf in ["wav", "flac", "mp3"]: for audio_path in tar_path.glob(f"**/*.{suf}"): convert_to_mono_in_place(audio_path)
cur_lang = content["label_lang"] initial_prompt = content["initial_prompt"]
transcribe_cmd = [ PYTHON, "tools/whisper_asr.py", "--model-size", label_model, "--device", label_device, "--audio-dir", tar_path, "--save-dir", tar_path, "--language", cur_lang, ]
if initial_prompt is not None: transcribe_cmd += ["--initial-prompt", initial_prompt]
if cur_lang != "IGNORE": try: gr.Warning("Begin To Transcribe") subprocess.run( transcribe_cmd, env=env, ) except Exception: print("Transcription error occurred")
elif content["type"] == "file" and item_path.is_file(): list_copy(item_path, content["method"])
return build_html_ok_message(i18n("Move files successfully")), new_explorer( data_path, max_depth=max_depth )
def generate_folder_name(): now = datetime.datetime.now() folder_name = now.strftime("%Y%m%d_%H%M%S") return folder_name
def train_process( data_path: str, option: str, # llama config llama_ckpt, llama_base_config, llama_lr, llama_maxsteps, llama_data_num_workers, llama_data_batch_size, llama_data_max_length, llama_precision, llama_check_interval, llama_grad_batches, llama_use_speaker, llama_use_lora,):
backend = "nccl" if sys.platform == "linux" else "gloo"
new_project = generate_folder_name() print("New Project Name: ", new_project)
if option == "VQGAN": msg = "Skipped VQGAN Training." gr.Warning(msg) logger.info(msg)
if option == "LLAMA": msg = "LLAMA Training begins..." gr.Warning(msg) logger.info(msg) subprocess.run( [ PYTHON, "tools/vqgan/extract_vq.py", str(data_pre_output), "--num-workers", "1", "--batch-size", "16", "--config-name", "firefly_gan_vq", "--checkpoint-path", "checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth", ] )
subprocess.run( [ PYTHON, "tools/llama/build_dataset.py", "--input", str(data_pre_output), "--text-extension", ".lab", "--num-workers", "16", ] ) ckpt_path = "checkpoints/fish-speech-1.4/model.pth" lora_prefix = "lora_" if llama_use_lora else "" llama_name = lora_prefix + "text2semantic_" + new_project latest = next( iter( sorted( [ str(p.relative_to("results")) for p in Path("results").glob(lora_prefix + "text2sem*/") ], reverse=True, ) ), llama_name, ) project = ( llama_name if llama_ckpt == i18n("new") else ( latest if llama_ckpt == i18n("latest") else Path(llama_ckpt).relative_to("results") ) ) logger.info(project)
if llama_check_interval > llama_maxsteps: llama_check_interval = llama_maxsteps
train_cmd = [ PYTHON, "fish_speech/train.py", "--config-name", "text2semantic_finetune", f"project={project}", f"trainer.strategy.process_group_backend={backend}", f"train_dataset.proto_files={str(['data/quantized-dataset-ft'])}", f"val_dataset.proto_files={str(['data/quantized-dataset-ft'])}", f"model.optimizer.lr={llama_lr}", f"trainer.max_steps={llama_maxsteps}", f"data.num_workers={llama_data_num_workers}", f"data.batch_size={llama_data_batch_size}", f"max_length={llama_data_max_length}", f"trainer.precision={llama_precision}", f"trainer.val_check_interval={llama_check_interval}", f"trainer.accumulate_grad_batches={llama_grad_batches}", f"train_dataset.interactive_prob={llama_use_speaker}", ] + ([f"+lora@model.model.lora_config=r_8_alpha_16"] if llama_use_lora else []) logger.info(train_cmd) subprocess.run(train_cmd)
return build_html_ok_message(i18n("Training stopped"))
def tensorboard_process( if_tensorboard: bool, tensorboard_dir: str, host: str, port: str,): global p_tensorboard if if_tensorboard == True and p_tensorboard == None: url = f"http://{host}:{port}" yield build_html_ok_message( i18n("Tensorboard interface is launched at {}").format(url) ) prefix = ["tensorboard"] if Path("fishenv").exists(): prefix = ["fishenv/env/python.exe", "fishenv/env/Scripts/tensorboard.exe"]
p_tensorboard = subprocess.Popen( prefix + [ "--logdir", tensorboard_dir, "--host", host, "--port", port, "--reload_interval", "120", ] ) elif if_tensorboard == False and p_tensorboard != None: kill_process(p_tensorboard.pid) p_tensorboard = None yield build_html_error_message(i18n("Tensorboard interface is closed"))
def fresh_tb_dir(): return gr.Dropdown( choices=[str(p) for p in Path("results").glob("**/tensorboard/")] )
def list_decoder_models(): paths = [str(p) for p in Path("checkpoints").glob("fish*/firefly*.pth")] if not paths: logger.warning("No decoder model found") return paths
def list_llama_models(): choices = [str(p.parent) for p in Path("checkpoints").glob("merged*/*model*.pth")] choices += [str(p.parent) for p in Path("checkpoints").glob("fish*/*model*.pth")] choices += [str(p.parent) for p in Path("checkpoints").glob("fs*/*model*.pth")] choices = sorted(choices, reverse=True) if not choices: logger.warning("No LLaMA model found") return choices
def list_lora_llama_models(): choices = sorted( [str(p) for p in Path("results").glob("lora*/**/*.ckpt")], reverse=True ) if not choices: logger.warning("No LoRA LLaMA model found") return choices
def fresh_decoder_model(): return gr.Dropdown(choices=list_decoder_models())
def fresh_llama_ckpt(llama_use_lora): return gr.Dropdown( choices=[i18n("latest"), i18n("new")] + ( [str(p) for p in Path("results").glob("text2sem*/")] if not llama_use_lora else [str(p) for p in Path("results").glob("lora_*/")] ) )
def fresh_llama_model(): return gr.Dropdown(choices=list_llama_models())
def llama_lora_merge(llama_weight, lora_llama_config, lora_weight, llama_lora_output): if ( lora_weight is None or not Path(lora_weight).exists() or not Path(llama_weight).exists() ): return build_html_error_message( i18n( "Path error, please check the model file exists in the corresponding path" ) ) gr.Warning("Merging begins...") merge_cmd = [ PYTHON, "tools/llama/merge_lora.py", "--lora-config", "r_8_alpha_16", "--lora-weight", lora_weight, "--output", llama_lora_output + "_" + generate_folder_name(), ] logger.info(merge_cmd) subprocess.run(merge_cmd) return build_html_ok_message(i18n("Merge successfully"))
def llama_quantify(llama_weight, quantify_mode): if llama_weight is None or not Path(llama_weight).exists(): return build_html_error_message( i18n( "Path error, please check the model file exists in the corresponding path" ) )
gr.Warning("Quantifying begins...")
now = generate_folder_name() quantify_cmd = [ PYTHON, "tools/llama/quantize.py", "--checkpoint-path", llama_weight, "--mode", quantify_mode, "--timestamp", now, ] logger.info(quantify_cmd) subprocess.run(quantify_cmd) if quantify_mode == "int8": quantize_path = str( Path(os.getcwd()) / "checkpoints" / f"fs-1.2-{quantify_mode}-{now}" ) else: quantize_path = str( Path(os.getcwd()) / "checkpoints" / f"fs-1.2-{quantify_mode}-g128-{now}" ) return build_html_ok_message( i18n("Quantify successfully") + f"Path: {quantize_path}" )
init_vqgan_yml = load_yaml_data_in_fact(vqgan_yml_path)init_llama_yml = load_yaml_data_in_fact(llama_yml_path)
with gr.Blocks( head="<style>\n" + css + "\n</style>", js=js, theme=seafoam, analytics_enabled=False, title="Fish Speech",) as demo: with gr.Row(): with gr.Column(): with gr.Tab("\U0001F4D6 " + i18n("Data Preprocessing")): with gr.Row(): textbox = gr.Textbox( label="\U0000270F " + i18n("Input Audio & Source Path for Transcription"), info=i18n("Speaker is identified by the folder name"), interactive=True, ) with gr.Row(equal_height=False): with gr.Column(): output_radio = gr.Radio( label="\U0001F4C1 " + i18n("Select source file processing method"), choices=[i18n("Copy"), i18n("Move")], value=i18n("Copy"), interactive=True, ) with gr.Column(): error = gr.HTML(label=i18n("Error Message")) if_label = gr.Checkbox( label=i18n("Open Labeler WebUI"), scale=0, show_label=True )
with gr.Row(): label_device = gr.Dropdown( label=i18n("Labeling Device"), info=i18n( "It is recommended to use CUDA, if you have low configuration, use CPU" ), choices=["cpu", "cuda"], value="cuda", interactive=True, ) label_model = gr.Dropdown( label=i18n("Whisper Model"), info=i18n("Faster Whisper, Up to 5g GPU memory usage"), choices=["large-v3", "medium"], value="large-v3", interactive=True, ) label_radio = gr.Dropdown( label=i18n("Optional Label Language"), info=i18n( "If there is no corresponding text for the audio, apply ASR for assistance, support .txt or .lab format" ), choices=[ (i18n("Chinese"), "zh"), (i18n("English"), "en"), (i18n("Japanese"), "ja"), (i18n("Disabled"), "IGNORE"), (i18n("auto"), "auto"), ], value="IGNORE", interactive=True, )
with gr.Row(): if_initial_prompt = gr.Checkbox( value=False, label=i18n("Enable Initial Prompt"), min_width=120, scale=0, ) initial_prompt = gr.Textbox( label=i18n("Initial Prompt"), info=i18n( "Initial prompt can provide contextual or vocabulary-specific guidance to the model." ), placeholder="This audio introduces the basic concepts and applications of artificial intelligence and machine learning.", interactive=False, )
with gr.Row(): add_button = gr.Button( "\U000027A1 " + i18n("Add to Processing Area"), variant="primary", ) remove_button = gr.Button( "\U000026D4 " + i18n("Remove Selected Data") )
with gr.Tab("\U0001F6E0 " + i18n("Training Configuration")): with gr.Row(): model_type_radio = gr.Radio( label=i18n( "Select the model to be trained (Depending on the Tab page you are on)" ), interactive=False, choices=["VQGAN", "LLAMA"], value="VQGAN", ) with gr.Row(): with gr.Tabs(): with gr.Tab(label=i18n("VQGAN Configuration")) as vqgan_page: gr.HTML("You don't need to train this model!")
with gr.Tab(label=i18n("LLAMA Configuration")) as llama_page: with gr.Row(equal_height=False): llama_use_lora = gr.Checkbox( label=i18n("Use LoRA"), info=i18n( "Use LoRA can save GPU memory, but may reduce the quality of the model" ), value=True, interactive=True, ) llama_ckpt = gr.Dropdown( label=i18n("Select LLAMA ckpt"), choices=[i18n("latest"), i18n("new")] + [ str(p) for p in Path("results").glob("text2sem*/") ] + [str(p) for p in Path("results").glob("lora*/")], value=i18n("latest"), interactive=True, ) with gr.Row(equal_height=False): llama_lr_slider = gr.Slider( label=i18n("Initial Learning Rate"), info=i18n( "lr smaller -> usually train slower but more stable" ), interactive=True, minimum=1e-5, maximum=1e-4, step=1e-5, value=5e-5, ) llama_maxsteps_slider = gr.Slider( label=i18n("Maximum Training Steps"), info=i18n( "recommend: max_steps = num_audios // batch_size * (2 to 5)" ), interactive=True, minimum=1, maximum=10000, step=1, value=50, ) with gr.Row(equal_height=False): llama_base_config = gr.Dropdown( label=i18n("Model Size"), choices=[ "text2semantic_finetune", ], value="text2semantic_finetune", ) llama_data_num_workers_slider = gr.Slider( label=i18n("Number of Workers"), minimum=1, maximum=32, step=1, value=4, ) with gr.Row(equal_height=False): llama_data_batch_size_slider = gr.Slider( label=i18n("Batch Size"), interactive=True, minimum=1, maximum=32, step=1, value=4, ) llama_data_max_length_slider = gr.Slider( label=i18n("Maximum Length per Sample"), interactive=True, minimum=1024, maximum=4096, step=128, value=1024, ) with gr.Row(equal_height=False): llama_precision_dropdown = gr.Dropdown( label=i18n("Precision"), info=i18n( "bf16-true is recommended for 30+ series GPU, 16-mixed is recommended for 10+ series GPU" ), interactive=True, choices=["32", "bf16-true", "16-mixed"], value="bf16-true", ) llama_check_interval_slider = gr.Slider( label=i18n("Save model every n steps"), info=i18n( "make sure that it's not greater than max_steps" ), interactive=True, minimum=1, maximum=1000, step=1, value=50, ) with gr.Row(equal_height=False): llama_grad_batches = gr.Slider( label=i18n("Accumulate Gradient Batches"), interactive=True, minimum=1, maximum=20, step=1, value=init_llama_yml["trainer"][ "accumulate_grad_batches" ], ) llama_use_speaker = gr.Slider( label=i18n( "Probability of applying Speaker Condition" ), interactive=True, minimum=0.1, maximum=1.0, step=0.05, value=init_llama_yml["train_dataset"][ "interactive_prob" ], )
with gr.Tab(label=i18n("Merge LoRA"), id=4): with gr.Row(equal_height=False): llama_weight = gr.Dropdown( label=i18n("Base LLAMA Model"), info=i18n( "Type the path or select from the dropdown" ), choices=[ "checkpoints/fish-speech-1.4/model.pth", ], value="checkpoints/fish-speech-1.4/model.pth", allow_custom_value=True, interactive=True, ) with gr.Row(equal_height=False): lora_weight = gr.Dropdown( label=i18n("LoRA Model to be merged"), info=i18n( "Type the path or select from the dropdown" ), choices=[ str(p) for p in Path("results").glob("lora*/**/*.ckpt") ], allow_custom_value=True, interactive=True, ) lora_llama_config = gr.Dropdown( label=i18n("LLAMA Model Config"), info=i18n( "Type the path or select from the dropdown" ), choices=[ "text2semantic_finetune", ], value="text2semantic_finetune", allow_custom_value=True, ) with gr.Row(equal_height=False): llama_lora_output = gr.Dropdown( label=i18n("Output Path"), info=i18n( "Type the path or select from the dropdown" ), value="checkpoints/merged", choices=["checkpoints/merged"], allow_custom_value=True, interactive=True, ) with gr.Row(equal_height=False): llama_lora_merge_btn = gr.Button( value=i18n("Merge"), variant="primary" )
with gr.Tab(label=i18n("Model Quantization"), id=5): with gr.Row(equal_height=False): llama_weight_to_quantify = gr.Dropdown( label=i18n("Base LLAMA Model"), info=i18n( "Type the path or select from the dropdown" ), choices=list_llama_models(), value="checkpoints/fish-speech-1.4", allow_custom_value=True, interactive=True, ) quantify_mode = gr.Dropdown( label=i18n("Post-quantification Precision"), info=i18n( "The lower the quantitative precision, the more the effectiveness may decrease, but the greater the efficiency will increase" ), choices=["int8", "int4"], value="int8", allow_custom_value=False, interactive=True, ) with gr.Row(equal_height=False): llama_quantify_btn = gr.Button( value=i18n("Quantify"), variant="primary" )
with gr.Tab(label="Tensorboard", id=6): with gr.Row(equal_height=False): tb_host = gr.Textbox( label=i18n("Tensorboard Host"), value="127.0.0.1" ) tb_port = gr.Textbox( label=i18n("Tensorboard Port"), value="11451" ) with gr.Row(equal_height=False): tb_dir = gr.Dropdown( label=i18n("Tensorboard Log Path"), allow_custom_value=True, choices=[ str(p) for p in Path("results").glob("**/tensorboard/") ], ) with gr.Row(equal_height=False): if_tb = gr.Checkbox( label=i18n("Open Tensorboard"), )
with gr.Tab("\U0001F9E0 " + i18n("Inference Configuration")): with gr.Column(): with gr.Row(): with gr.Accordion( label="\U0001F5A5 " + i18n("Inference Server Configuration"), open=False, ): with gr.Row(): infer_host_textbox = gr.Textbox( label=i18n("WebUI Host"), value="127.0.0.1" ) infer_port_textbox = gr.Textbox( label=i18n("WebUI Port"), value="7862" ) with gr.Row(): infer_decoder_model = gr.Dropdown( label=i18n("Decoder Model Path"), info=i18n( "Type the path or select from the dropdown" ), choices=list_decoder_models(), value="checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth", allow_custom_value=True, ) infer_decoder_config = gr.Dropdown( label=i18n("Decoder Model Config"), info=i18n("Changing with the Model Path"), value="firefly_gan_vq", choices=[ "firefly_gan_vq", ], allow_custom_value=True, ) with gr.Row(): infer_llama_model = gr.Dropdown( label=i18n("LLAMA Model Path"), info=i18n( "Type the path or select from the dropdown" ), value="checkpoints/fish-speech-1.4", choices=list_llama_models(), allow_custom_value=True, )
with gr.Row(): infer_compile = gr.Radio( label=i18n("Compile Model"), info=i18n( "Compile the model can significantly reduce the inference time, but will increase cold start time" ), choices=["Yes", "No"], value=( "Yes" if (sys.platform == "linux") else "No" ), interactive=is_module_installed("triton"), )
with gr.Row(): infer_checkbox = gr.Checkbox( label=i18n("Open Inference Server") ) infer_error = gr.HTML(label=i18n("Inference Server Error"))
with gr.Column(): train_error = gr.HTML(label=i18n("Training Error")) checkbox_group = gr.CheckboxGroup( label="\U0001F4CA " + i18n("Data Source"), info=i18n( "The path of the input folder on the left or the filelist. Whether checked or not, it will be used for subsequent training in this list." ), elem_classes=["data_src"], ) train_box = gr.Textbox( label=i18n("Data Preprocessing Path"), value=str(data_pre_output), interactive=False, ) model_box = gr.Textbox( label="\U0001F4BE " + i18n("Model Output Path"), value=str(default_model_output), interactive=False, )
with gr.Accordion( i18n( "View the status of the preprocessing folder (use the slider to control the depth of the tree)" ), elem_classes=["scrollable-component"], elem_id="file_accordion", ): tree_slider = gr.Slider( minimum=0, maximum=3, value=0, step=1, show_label=False, container=False, ) file_markdown = new_explorer(str(data_pre_output), 0) with gr.Row(equal_height=False): admit_btn = gr.Button( "\U00002705 " + i18n("File Preprocessing"), variant="primary", ) fresh_btn = gr.Button("\U0001F503", scale=0, min_width=80) help_button = gr.Button("\U00002753", scale=0, min_width=80) # question train_btn = gr.Button(i18n("Start Training"), variant="primary")
footer = load_data_in_raw("fish_speech/webui/html/footer.html") footer = footer.format( versions=versions_html(), api_docs="https://speech.fish.audio/inference/#http-api", ) gr.HTML(footer, elem_id="footer") vqgan_page.select(lambda: "VQGAN", None, model_type_radio) llama_page.select(lambda: "LLAMA", None, model_type_radio) add_button.click( fn=add_item, inputs=[textbox, output_radio, label_radio, if_initial_prompt, initial_prompt], outputs=[checkbox_group, error], ) remove_button.click( fn=remove_items, inputs=[checkbox_group], outputs=[checkbox_group, error] ) checkbox_group.change(fn=show_selected, inputs=checkbox_group, outputs=[error]) help_button.click( fn=None, js='() => { window.open("https://speech.fish.audio/", "newwindow", "height=100, width=400, ' 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")}', ) if_label.change(fn=change_label, inputs=[if_label], outputs=[error]) if_initial_prompt.change( fn=lambda x: gr.Textbox(value="", interactive=x), inputs=[if_initial_prompt], outputs=[initial_prompt], ) train_btn.click( fn=train_process, inputs=[ train_box, model_type_radio, # llama config llama_ckpt, llama_base_config, llama_lr_slider, llama_maxsteps_slider, llama_data_num_workers_slider, llama_data_batch_size_slider, llama_data_max_length_slider, llama_precision_dropdown, llama_check_interval_slider, llama_grad_batches, llama_use_speaker, llama_use_lora, ], outputs=[train_error], ) if_tb.change( fn=tensorboard_process, inputs=[if_tb, tb_dir, tb_host, tb_port], outputs=[train_error], ) tb_dir.change(fn=fresh_tb_dir, inputs=[], outputs=[tb_dir]) infer_decoder_model.change( fn=fresh_decoder_model, inputs=[], outputs=[infer_decoder_model] ) infer_llama_model.change( fn=fresh_llama_model, inputs=[], outputs=[infer_llama_model] ) llama_weight.change(fn=fresh_llama_model, inputs=[], outputs=[llama_weight]) admit_btn.click( fn=check_files, inputs=[train_box, tree_slider, label_model, label_device], outputs=[error, file_markdown], ) fresh_btn.click( fn=new_explorer, inputs=[train_box, tree_slider], outputs=[file_markdown] ) llama_use_lora.change( fn=fresh_llama_ckpt, inputs=[llama_use_lora], outputs=[llama_ckpt] ) llama_ckpt.change( fn=fresh_llama_ckpt, inputs=[llama_use_lora], outputs=[llama_ckpt] ) lora_weight.change( fn=lambda: gr.Dropdown(choices=list_lora_llama_models()), inputs=[], outputs=[lora_weight], ) llama_lora_merge_btn.click( fn=llama_lora_merge, inputs=[llama_weight, lora_llama_config, lora_weight, llama_lora_output], outputs=[train_error], ) llama_quantify_btn.click( fn=llama_quantify, inputs=[llama_weight_to_quantify, quantify_mode], outputs=[train_error], ) infer_checkbox.change( fn=change_infer, inputs=[ infer_checkbox, infer_host_textbox, infer_port_textbox, infer_decoder_model, infer_decoder_config, infer_llama_model, infer_compile, ], outputs=[infer_error], )
demo.launch(inbrowser=True)23 unmodified lines2425262723 unmodified linesspaces>=0.26.1einx[torch]==0.2.0openccfaster-whisper23 unmodified lines242526272823 unmodified linesspaces>=0.26.1einx[torch]==0.2.0openccfaster-whisperormsgpack
2 unmodified lines345678910111213141516171819202122232 unmodified lines2627282930313233343536373841 unmodified lines8081828384858687888990919239 unmodified lines1321331341351361371381 unmodified line1401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961976 unmodified lines2042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382 unmodified lines24124224324424524624718 unmodified lines26626726826927027127221 unmodified lines2942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323332 unmodified lines33633733833934034134234334452 unmodified lines3973983994004014024034044054064074084094104114124134144157 unmodified lines42342442542642742842943043143243343443543643743843944020 unmodified lines4614624634644654664674684694704714724734744754764774782 unmodified linesimport jsonimport queueimport randomimport tracebackimport wavefrom argparse import ArgumentParserfrom http import HTTPStatusfrom pathlib import Pathfrom typing import Annotated, Literal, Optionalimport librosaimport numpy as npimport pyrootutilsimport soundfile as sfimport torchfrom kui.asgi import (Body,HTTPException,HttpView,JSONResponse,Kui,2 unmodified lines)from kui.asgi.routing import MultimethodRoutesfrom loguru import loggerfrom pydantic import BaseModel, Fieldpyrootutils.setup_root(__file__, indicator=".project-root", pythonpath=True)# from fish_speech.models.vqgan.lit_module import VQGANfrom fish_speech.models.vqgan.modules.firefly import FireflyArchitecturefrom tools.auto_rerank import batch_asr, calculate_wer, is_chinese, load_modelfrom tools.llama.generate import (GenerateRequest,GenerateResponse,41 unmodified linesdef load_audio(reference_audio, sr):if len(reference_audio) > 255 or not Path(reference_audio).exists():try:audio_data = base64.b64decode(reference_audio)reference_audio = io.BytesIO(audio_data)except base64.binascii.Error:raise ValueError("Invalid path or base64 string")audio, _ = librosa.load(reference_audio, sr=sr, mono=True)return audio39 unmodified linesreturn decoder_model.decode(indices=codes[None],feature_lengths=feature_lengths,).squeeze()raise ValueError(f"Unknown model type: {type(decoder_model)}")1 unmodified lineroutes = MultimethodRoutes(base_class=HttpView)def get_random_paths(base_path, data, speaker, emotion):if base_path and data and speaker and emotion and (Path(base_path).exists()):if speaker in data and emotion in data[speaker]:files = data[speaker][emotion]lab_files = [f for f in files if f.endswith(".lab")]wav_files = [f for f in files if f.endswith(".wav")]if lab_files and wav_files:selected_lab = random.choice(lab_files)selected_wav = random.choice(wav_files)lab_path = Path(base_path) / speaker / emotion / selected_labwav_path = Path(base_path) / speaker / emotion / selected_wavif lab_path.exists() and wav_path.exists():return lab_path, wav_pathreturn None, Nonedef load_json(json_file):if not json_file:logger.info("Not using a json file")return Nonetry:with open(json_file, "r", encoding="utf-8") as file:data = json.load(file)except FileNotFoundError:logger.warning(f"ref json not found: {json_file}")data = Noneexcept Exception as e:logger.warning(f"Loading json failed: {e}")data = Nonereturn dataclass InvokeRequest(BaseModel):text: str = "你说的对, 但是原神是一款由米哈游自主研发的开放世界手游."reference_text: Optional[str] = Nonereference_audio: Optional[str] = Nonemax_new_tokens: int = 1024chunk_length: Annotated[int, Field(ge=0, le=500, strict=True)] = 100top_p: Annotated[float, Field(ge=0.1, le=1.0, strict=True)] = 0.7repetition_penalty: Annotated[float, Field(ge=0.9, le=2.0, strict=True)] = 1.2temperature: Annotated[float, Field(ge=0.1, le=1.0, strict=True)] = 0.7emotion: Optional[str] = Noneformat: Literal["wav", "mp3", "flac"] = "wav"streaming: bool = Falseref_json: Optional[str] = "ref_data.json"ref_base: Optional[str] = "ref_data"speaker: Optional[str] = Nonedef get_content_type(audio_format):if audio_format == "wav":return "audio/wav"6 unmodified lines@torch.inference_mode()def inference(req: InvokeRequest):# Parse reference audio aka promptprompt_tokens = Noneref_data = load_json(req.ref_json)ref_base = req.ref_baselab_path, wav_path = get_random_paths(ref_base, ref_data, req.speaker, req.emotion)if lab_path and wav_path:with open(lab_path, "r", encoding="utf-8") as lab_file:ref_text = lab_file.read()req.reference_audio = wav_pathreq.reference_text = ref_textlogger.info("ref_path: " + str(wav_path))logger.info("ref_text: " + ref_text)# Parse reference audio aka promptprompt_tokens = encode_reference(decoder_model=decoder_model,reference_audio=req.reference_audio,enable_reference_audio=req.reference_audio is not None,)logger.info(f"ref_text: {req.reference_text}")# LLAMA Inferencerequest = dict(device=decoder_model.device,max_new_tokens=req.max_new_tokens,text=req.text,top_p=req.top_p,repetition_penalty=req.repetition_penalty,temperature=req.temperature,2 unmodified lineschunk_length=req.chunk_length,max_length=2048,prompt_tokens=prompt_tokens,prompt_text=req.reference_text,)response_queue = queue.Queue()18 unmodified linesif result.action == "next":breakwith torch.autocast(device_type=decoder_model.device.type, dtype=args.precision):fake_audios = decode_vq_tokens(21 unmodified linesyield fake_audiosdef auto_rerank_inference(req: InvokeRequest, use_auto_rerank: bool = True):if not use_auto_rerank:# 如果不使用 auto_rerank,直接调用原始的 inference 函数return inference(req)zh_model, en_model = load_model()max_attempts = 5best_wer = float("inf")best_audio = Nonefor attempt in range(max_attempts):# 调用原始的 inference 函数audio_generator = inference(req)fake_audios = next(audio_generator)asr_result = batch_asr(zh_model if is_chinese(req.text) else en_model, [fake_audios], 44100)[0]wer = calculate_wer(req.text, asr_result["text"])if wer <= 0.1 and not asr_result["huge_gap"]:return fake_audiosif wer < best_wer:best_wer = werbest_audio = fake_audiosif attempt == max_attempts - 1:breakreturn best_audioasync def inference_async(req: InvokeRequest):for chunk in inference(req):yield chunk2 unmodified linesyield buffer@routes.http.post("/v1/invoke")async def api_invoke_model(req: Annotated[InvokeRequest, Body(exclusive=True)],):"""Invoke model and generate audio52 unmodified linesparser.add_argument("--llama-checkpoint-path",type=str,default="checkpoints/fish-speech-1.2-sft",)parser.add_argument("--decoder-checkpoint-path",type=str,default="checkpoints/fish-speech-1.2-sft/firefly-gan-vq-fsq-4x1024-42hz-generator.pth",)parser.add_argument("--decoder-config-name", type=str, default="firefly_gan_vq")parser.add_argument("--device", type=str, default="cuda")parser.add_argument("--half", action="store_true")parser.add_argument("--compile", action="store_true")parser.add_argument("--max-text-length", type=int, default=0)parser.add_argument("--listen", type=str, default="127.0.0.1:8000")parser.add_argument("--workers", type=int, default=1)parser.add_argument("--use-auto-rerank", type=bool, default=True)7 unmodified lines},).routesapp = Kui(routes=routes + openapi[1:], # Remove the default routeexception_handlers={HTTPException: http_execption_handler,Exception: other_exception_handler,},cors_config={},)if __name__ == "__main__":import threadingimport uvicorn20 unmodified lines# Dry run to check if the model is loaded correctly and avoid the first-time latencylist(inference(InvokeRequest(text="Hello world.",reference_text=None,reference_audio=None,max_new_tokens=0,top_p=0.7,repetition_penalty=1.2,temperature=0.7,emotion=None,format="wav",ref_base=None,ref_json=None,)))2 unmodified lines3456789101112131415161718192021222324252627282 unmodified lines3132333435363738394041424344454641 unmodified lines88899091929394959697989910010110210310410510610710839 unmodified lines1481491501511521531541 unmodified line1561571581591601616 unmodified lines1681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192 unmodified lines22222322422522622722818 unmodified lines24724824925025125225321 unmodified lines2752762772782792802812 unmodified lines28428528628728828929029129252 unmodified lines3453463473483493503513523533543553563573583593603613623637 unmodified lines37137237337437537637737837938038138238338438538638738838939039139239339439539639739839940020 unmodified lines4214224234244254264274284294304314324334344354362 unmodified linesimport jsonimport queueimport randomimport sysimport tracebackimport wavefrom argparse import ArgumentParserfrom http import HTTPStatusfrom pathlib import Pathfrom typing import Annotated, Any, Literal, Optionalimport numpy as npimport ormsgpackimport pyrootutilsimport soundfile as sfimport torchimport torchaudiofrom baize.datastructures import ContentTypefrom kui.asgi import (Body,FactoryClass,HTTPException,HttpRequest,HttpView,JSONResponse,Kui,2 unmodified lines)from kui.asgi.routing import MultimethodRoutesfrom loguru import loggerfrom pydantic import BaseModel, Field, conintpyrootutils.setup_root(__file__, indicator=".project-root", pythonpath=True)# from fish_speech.models.vqgan.lit_module import VQGANfrom fish_speech.models.vqgan.modules.firefly import FireflyArchitecturefrom fish_speech.text.chn_text_norm.text import Text as ChnNormedTextfrom fish_speech.utils import autocast_exclude_mpsfrom tools.commons import ServeReferenceAudio, ServeTTSRequestfrom tools.file import AUDIO_EXTENSIONS, audio_to_bytes, list_files, read_ref_textfrom tools.llama.generate import (GenerateRequest,GenerateResponse,41 unmodified linesdef load_audio(reference_audio, sr):if len(reference_audio) > 255 or not Path(reference_audio).exists():audio_data = reference_audioreference_audio = io.BytesIO(audio_data)waveform, original_sr = torchaudio.load(reference_audio, backend="sox" if sys.platform == "linux" else "soundfile")if waveform.shape[0] > 1:waveform = torch.mean(waveform, dim=0, keepdim=True)if original_sr != sr:resampler = torchaudio.transforms.Resample(orig_freq=original_sr, new_freq=sr)waveform = resampler(waveform)audio = waveform.squeeze().numpy()return audio39 unmodified linesreturn decoder_model.decode(indices=codes[None],feature_lengths=feature_lengths,)[0].squeeze()raise ValueError(f"Unknown model type: {type(decoder_model)}")1 unmodified lineroutes = MultimethodRoutes(base_class=HttpView)def get_content_type(audio_format):if audio_format == "wav":return "audio/wav"6 unmodified lines@torch.inference_mode()def inference(req: ServeTTSRequest):idstr: str | None = req.reference_idif idstr is not None:ref_folder = Path("references") / idstrref_folder.mkdir(parents=True, exist_ok=True)ref_audios = list_files(ref_folder, AUDIO_EXTENSIONS, recursive=True, sort=False)prompt_tokens = [encode_reference(decoder_model=decoder_model,reference_audio=audio_to_bytes(str(ref_audio)),enable_reference_audio=True,)for ref_audio in ref_audios]prompt_texts = [read_ref_text(str(ref_audio.with_suffix(".lab")))for ref_audio in ref_audios]else:# Parse reference audio aka promptrefs = req.referencesif refs is None:refs = []prompt_tokens = [encode_reference(decoder_model=decoder_model,reference_audio=ref.audio,enable_reference_audio=True,)for ref in refs]prompt_texts = [ref.text for ref in refs]# LLAMA Inferencerequest = dict(device=decoder_model.device,max_new_tokens=req.max_new_tokens,text=(req.textif not req.normalizeelse ChnNormedText(raw_text=req.text).normalize()),top_p=req.top_p,repetition_penalty=req.repetition_penalty,temperature=req.temperature,2 unmodified lineschunk_length=req.chunk_length,max_length=2048,prompt_tokens=prompt_tokens,prompt_text=prompt_texts,)response_queue = queue.Queue()18 unmodified linesif result.action == "next":breakwith autocast_exclude_mps(device_type=decoder_model.device.type, dtype=args.precision):fake_audios = decode_vq_tokens(21 unmodified linesyield fake_audiosasync def inference_async(req: ServeTTSRequest):for chunk in inference(req):yield chunk2 unmodified linesyield buffer@routes.http.post("/v1/tts")async def api_invoke_model(req: Annotated[ServeTTSRequest, Body(exclusive=True)],):"""Invoke model and generate audio52 unmodified linesparser.add_argument("--llama-checkpoint-path",type=str,default="checkpoints/fish-speech-1.4",)parser.add_argument("--decoder-checkpoint-path",type=str,default="checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth",)parser.add_argument("--decoder-config-name", type=str, default="firefly_gan_vq")parser.add_argument("--device", type=str, default="cuda")parser.add_argument("--half", action="store_true")parser.add_argument("--compile", action="store_true")parser.add_argument("--max-text-length", type=int, default=0)parser.add_argument("--listen", type=str, default="127.0.0.1:8080")parser.add_argument("--workers", type=int, default=1)parser.add_argument("--use-auto-rerank", type=bool, default=True)7 unmodified lines},).routesclass MsgPackRequest(HttpRequest):async def data(self) -> Annotated[Any, ContentType("application/msgpack")]:if self.content_type == "application/msgpack":return ormsgpack.unpackb(await self.body)raise HTTPException(HTTPStatus.UNSUPPORTED_MEDIA_TYPE,headers={"Accept": "application/msgpack"},)app = Kui(routes=routes + openapi[1:], # Remove the default routeexception_handlers={HTTPException: http_execption_handler,Exception: other_exception_handler,},factory_class=FactoryClass(http=MsgPackRequest),cors_config={},)if __name__ == "__main__":import uvicorn20 unmodified lines# Dry run to check if the model is loaded correctly and avoid the first-time latencylist(inference(ServeTTSRequest(text="Hello world.",references=[],reference_id=None,max_new_tokens=0,top_p=0.7,repetition_penalty=1.2,temperature=0.7,emotion=None,format="wav",)))
1234567891011121314151617181920212223242526272829303132333435from typing import Annotated, Literal, Optional
from pydantic import BaseModel, Field, conint
class ServeReferenceAudio(BaseModel): audio: bytes text: str
class ServeTTSRequest(BaseModel): text: str chunk_length: Annotated[int, conint(ge=100, le=300, strict=True)] = 200 # Audio format format: Literal["wav", "pcm", "mp3"] = "wav" mp3_bitrate: Literal[64, 128, 192] = 128 # References audios for in-context learning references: list[ServeReferenceAudio] = [] # Reference id # For example, if you want use https://fish.audio/m/7f92f8afb8ec43bf81429cc1c9199cb1/ # Just pass 7f92f8afb8ec43bf81429cc1c9199cb1 reference_id: str | None = None # Normalize text for en & zh, this increase stability for numbers normalize: bool = True mp3_bitrate: Optional[int] = 64 opus_bitrate: Optional[int] = -1000 # Balance mode will reduce latency to 300ms, but may decrease stability latency: Literal["normal", "balanced"] = "normal" # not usually used below streaming: bool = False emotion: Optional[str] = None max_new_tokens: int = 1024 top_p: Annotated[float, Field(ge=0.1, le=1.0, strict=True)] = 0.7 repetition_penalty: Annotated[float, Field(ge=0.9, le=2.0, strict=True)] = 1.2 temperature: Annotated[float, Field(ge=0.1, le=1.0, strict=True)] = 0.712345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import os
from huggingface_hub import hf_hub_download
# Downloaddef check_and_download_files(repo_id, file_list, local_dir): os.makedirs(local_dir, exist_ok=True) for file in file_list: file_path = os.path.join(local_dir, file) if not os.path.exists(file_path): print(f"{file} 不存在,从 Hugging Face 仓库下载...") hf_hub_download( repo_id=repo_id, filename=file, resume_download=True, local_dir=local_dir, local_dir_use_symlinks=False, ) else: print(f"{file} 已存在,跳过下载。")
# 1strepo_id_1 = "fishaudio/fish-speech-1.4"local_dir_1 = "./checkpoints/fish-speech-1.4"files_1 = [ "model.pth", "README.md", "special_tokens_map.json", "tokenizer_config.json", "tokenizer.json", "config.json", "firefly-gan-vq-fsq-8x1024-21hz-generator.pth",]
# 3rdrepo_id_3 = "fishaudio/fish-speech-1"local_dir_3 = "./"files_3 = [ "ffmpeg.exe", "ffprobe.exe",]
# 4threpo_id_4 = "SpicyqSama007/fish-speech-packed"local_dir_4 = "./"files_4 = [ "asr-label-win-x64.exe",]
check_and_download_files(repo_id_1, files_1, local_dir_1)
check_and_download_files(repo_id_3, files_3, local_dir_3)check_and_download_files(repo_id_4, files_4, local_dir_4)123456789101112131415161718192021import clickimport torchfrom loguru import logger
@click.command()@click.argument("model_path")@click.argument("output_path")def main(model_path, output_path): if model_path == output_path: logger.error("Model path and output path are the same") return
logger.info(f"Loading model from {model_path}") state_dict = torch.load(model_path, map_location="cpu")["state_dict"] torch.save(state_dict, output_path) logger.info(f"Model saved to {output_path}")
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import base64from pathlib import Pathfrom typing import Union
from loguru import loggerfrom natsort import natsorted
AUDIO_EXTENSIONS = { ".mp3", ".wav", ".flac", ".ogg", ".m4a", ".wma", ".aac", ".aiff", ".aif", ".aifc",}
VIDEO_EXTENSIONS = { ".mp4", ".avi",}
def audio_to_bytes(file_path): if not file_path or not Path(file_path).exists(): return None with open(file_path, "rb") as wav_file: wav = wav_file.read() return wav
def read_ref_text(ref_text): path = Path(ref_text) if path.exists() and path.is_file(): with path.open("r", encoding="utf-8") as file: return file.read() return ref_text
def list_files( path: Union[Path, str], extensions: set[str] = None, recursive: bool = False, sort: bool = True,) -> list[Path]: """List files in a directory.
Args: path (Path): Path to the directory. extensions (set, optional): Extensions to filter. Defaults to None. recursive (bool, optional): Whether to search recursively. Defaults to False. sort (bool, optional): Whether to sort the files. Defaults to True.
Returns: list: List of files. """
if isinstance(path, str): path = Path(path)
if not path.exists(): raise FileNotFoundError(f"Directory {path} does not exist.")
files = [file for ext in extensions for file in path.rglob(f"*{ext}")]
if sort: files = natsorted(files)
return files
def load_filelist(path: Path | str) -> list[tuple[Path, str, str, str]]: """ Load a Bert-VITS2 style filelist. """
files = set() results = [] count_duplicated, count_not_found = 0, 0
LANGUAGE_TO_LANGUAGES = { "zh": ["zh", "en"], "jp": ["jp", "en"], "en": ["en"], }
with open(path, "r", encoding="utf-8") as f: for line in f.readlines(): splits = line.strip().split("|", maxsplit=3) if len(splits) != 4: logger.warning(f"Invalid line: {line}") continue
filename, speaker, language, text = splits file = Path(filename) language = language.strip().lower()
if language == "ja": language = "jp"
assert language in ["zh", "jp", "en"], f"Invalid language {language}" languages = LANGUAGE_TO_LANGUAGES[language]
if file in files: logger.warning(f"Duplicated file: {file}") count_duplicated += 1 continue
if not file.exists(): logger.warning(f"File not found: {file}") count_not_found += 1 continue
results.append((file, speaker, languages, text))
if count_duplicated > 0: logger.warning(f"Total duplicated files: {count_duplicated}")
if count_not_found > 0: logger.warning(f"Total files not found: {count_not_found}")
return results12 unmodified lines1314151617181912 unmodified linesfrom fish_speech.datasets.protos.text_data_pb2 import Semantics, Sentence, TextDatafrom fish_speech.datasets.protos.text_data_stream import pack_pb_streamfrom fish_speech.utils.file import load_filelist# To avoid CPU overloados.environ["MKL_NUM_THREADS"] = "1"12 unmodified lines1314151617181912 unmodified linesfrom fish_speech.datasets.protos.text_data_pb2 import Semantics, Sentence, TextDatafrom fish_speech.datasets.protos.text_data_stream import pack_pb_streamfrom tools.file import load_filelist# To avoid CPU overloados.environ["MKL_NUM_THREADS"] = "1"
1 unmodified line23456785 unmodified lines9394959697989910010110210310410510610728 unmodified lines13613713813914014114214314414514634 unmodified lines181182183184185186187188167 unmodified lines356357358359360361362241 unmodified lines6046056066076086096101 unmodified lineimport queueimport threadingimport timefrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Literal, Optional, Tuple, Union85 unmodified lines**sampling_kwargs,) -> torch.Tensor:x = model.forward_generate(x, input_pos)codebooks = [sample(x.logits,previous_tokens=(previous_tokens[0] if previous_tokens is not None else None), # Disable repetition penalty for the token codebook**sampling_kwargs,)[0]]x = x.hidden_states# Cleanup the cache28 unmodified lines) -> torch.Tensor:x = model.forward_generate(x, input_pos)codebooks = [sample(x.token_logits,previous_tokens=None, # Disable repetition penalty for the token codebook**sampling_kwargs,)[0]]34 unmodified lineselse:window = previous_tokens[:, i - win_size : i]with torch.backends.cuda.sdp_kernel(enable_flash=False, enable_mem_efficient=False, enable_math=True): # Actually better for Inductor to codegen attention herenext_token = decode_one_token(model=model,167 unmodified linesif compile:logger.info("Compiling function...")decode_one_token = torch.compile(decode_one_token, mode="reduce-overhead", fullgraph=True)return model.eval(), decode_one_token241 unmodified lines@click.option("--checkpoint-path",type=click.Path(path_type=Path, exists=True),default="checkpoints/fish-speech-1.2-sft",)@click.option("--device", type=str, default="cuda")@click.option("--compile/--no-compile", default=False)1 unmodified line234567885 unmodified lines94959697989910010110210310410510610710810911011111211328 unmodified lines14214314414514614714814915015115215315415515615734 unmodified lines192193194195196197198199200201202203167 unmodified lines371372373374375376377378379380241 unmodified lines6226236246256266276281 unmodified lineimport queueimport threadingimport timefrom contextlib import nullcontextfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Literal, Optional, Tuple, Union85 unmodified lines**sampling_kwargs,) -> torch.Tensor:x = model.forward_generate(x, input_pos)sampling_kwargs_main = sampling_kwargs.copy()sampling_kwargs_main["temperature"] = 0.1sampling_kwargs_main["top_p"] = 0.1sampling_kwargs_main["repetition_penalty"] = 1.0codebooks = [sample(x.logits,previous_tokens=None, # Disable repetition penalty for the token codebook**sampling_kwargs_main,)[0]]x = x.hidden_states# Cleanup the cache28 unmodified lines) -> torch.Tensor:x = model.forward_generate(x, input_pos)sampling_kwargs_main = sampling_kwargs.copy()sampling_kwargs_main["temperature"] = 0.1sampling_kwargs_main["top_p"] = 0.1sampling_kwargs_main["repetition_penalty"] = 1.0codebooks = [sample(x.logits,previous_tokens=None, # Disable repetition penalty for the token codebook**sampling_kwargs_main,)[0]]34 unmodified lineselse:window = previous_tokens[:, i - win_size : i]with (torch.backends.cuda.sdp_kernel(enable_flash=False, enable_mem_efficient=False, enable_math=True)if torch.cuda.is_available()else nullcontext()): # Actually better for Inductor to codegen attention herenext_token = decode_one_token(model=model,167 unmodified linesif compile:logger.info("Compiling function...")decode_one_token = torch.compile(decode_one_token,fullgraph=True,backend="inductor" if torch.cuda.is_available() else "aot_eager",mode="reduce-overhead" if torch.cuda.is_available() else None,)return model.eval(), decode_one_token241 unmodified lines@click.option("--checkpoint-path",type=click.Path(path_type=Path, exists=True),default="checkpoints/fish-speech-1.4",)@click.option("--device", type=str, default="cuda")@click.option("--compile/--no-compile", default=False)
14 unmodified lines1516171819202114 unmodified lines@click.command()@click.option("--lora-config", type=str, default="r_8_alpha_16")@click.option("--base-weight", type=str, default="checkpoints/fish-speech-1.2-sft")@click.option("--lora-weight", type=str, required=True)@click.option("--output", type=str, required=True)def merge(lora_config, base_weight, lora_weight, output):14 unmodified lines1516171819202114 unmodified lines@click.command()@click.option("--lora-config", type=str, default="r_8_alpha_16")@click.option("--base-weight", type=str, default="checkpoints/fish-speech-1.4")@click.option("--lora-weight", type=str, required=True)@click.option("--output", type=str, required=True)def merge(lora_config, base_weight, lora_weight, output):
427 unmodified lines42842943043143243343416 unmodified lines451452453454455456457427 unmodified lines@click.option("--checkpoint-path",type=click.Path(path_type=Path, exists=True),default="checkpoints/fish-speech-1.2-sft",)@click.option("--mode", type=str, default="int8", help="type of quantization to perform"16 unmodified linesprecision=precision,compile=False,)vq_model = "firefly-gan-vq-fsq-4x1024-42hz-generator.pth"now = timestamp if timestamp != "None" else generate_folder_name()if mode == "int8":427 unmodified lines42842943043143243343416 unmodified lines451452453454455456457427 unmodified lines@click.option("--checkpoint-path",type=click.Path(path_type=Path, exists=True),default="checkpoints/fish-speech-1.4",)@click.option("--mode", type=str, default="int8", help="type of quantization to perform"16 unmodified linesprecision=precision,compile=False,)vq_model = "firefly-gan-vq-fsq-8x1024-21hz-generator.pth"now = timestamp if timestamp != "None" else generate_folder_name()if mode == "int8":
12345678910111213141516171819202122232425262728293031323334import httpximport ormsgpack
from tools.commons import ServeReferenceAudio, ServeTTSRequest
# priority: ref_id > referencesrequest = ServeTTSRequest( text="你说的对, 但是原神是一款由米哈游自主研发的开放世界手游.", # reference_id="114514", references=[ ServeReferenceAudio( audio=open("lengyue.wav", "rb").read(), text=open("lengyue.lab", "r", encoding="utf-8").read(), ) ], streaming=True,)
with ( httpx.Client() as client, open("hello.wav", "wb") as f,): with client.stream( "POST", "http://127.0.0.1:8080/v1/tts", content=ormsgpack.packb(request, option=ormsgpack.OPT_SERIALIZE_PYDANTIC), headers={ "authorization": "Bearer YOUR_API_KEY", "content-type": "application/msgpack", }, timeout=None, ) as response: for chunk in response.iter_bytes(): f.write(chunk)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205import argparseimport base64import wave
import ormsgpackimport pyaudioimport requestsfrom pydub import AudioSegmentfrom pydub.playback import play
from tools.commons import ServeReferenceAudio, ServeTTSRequestfrom tools.file import audio_to_bytes, read_ref_text
def parse_args():
parser = argparse.ArgumentParser( description="Send a WAV file and text to a server and receive synthesized audio." )
parser.add_argument( "--url", "-u", type=str, default="http://127.0.0.1:8080/v1/tts", help="URL of the server", ) parser.add_argument( "--text", "-t", type=str, required=True, help="Text to be synthesized" ) parser.add_argument( "--reference_id", "-id", type=str, default=None, help="ID of the reference model o be used for the speech", ) parser.add_argument( "--reference_audio", "-ra", type=str, nargs="+", default=None, help="Path to the WAV file", ) parser.add_argument( "--reference_text", "-rt", type=str, nargs="+", default=None, help="Reference text for voice synthesis", ) parser.add_argument( "--output", "-o", type=str, default="generated_audio", help="Output audio file name", ) parser.add_argument( "--play", type=bool, default=True, help="Whether to play audio after receiving data", ) parser.add_argument("--normalize", type=bool, default=True) parser.add_argument( "--format", type=str, choices=["wav", "mp3", "flac"], default="wav" ) parser.add_argument("--mp3_bitrate", type=int, default=64) parser.add_argument("--opus_bitrate", type=int, default=-1000) parser.add_argument("--latency", type=str, default="normal", help="延迟选项") parser.add_argument( "--max_new_tokens", type=int, default=1024, help="Maximum new tokens to generate", ) parser.add_argument( "--chunk_length", type=int, default=100, help="Chunk length for synthesis" ) parser.add_argument( "--top_p", type=float, default=0.7, help="Top-p sampling for synthesis" ) parser.add_argument( "--repetition_penalty", type=float, default=1.2, help="Repetition penalty for synthesis", ) parser.add_argument( "--temperature", type=float, default=0.7, help="Temperature for sampling" ) parser.add_argument( "--speaker", type=str, default=None, help="Speaker ID for voice synthesis" ) parser.add_argument("--emotion", type=str, default=None, help="Speaker's Emotion") parser.add_argument( "--streaming", type=bool, default=False, help="Enable streaming response" ) parser.add_argument( "--channels", type=int, default=1, help="Number of audio channels" ) parser.add_argument("--rate", type=int, default=44100, help="Sample rate for audio")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
idstr: str | None = args.reference_id # priority: ref_id > [{text, audio},...] if idstr is None: ref_audios = args.reference_audio ref_texts = args.reference_text if ref_audios is None: byte_audios = [] else: byte_audios = [audio_to_bytes(ref_audio) for ref_audio in ref_audios] if ref_texts is None: ref_texts = [] else: ref_texts = [read_ref_text(ref_text) for ref_text in ref_texts] else: byte_audios = [] ref_texts = [] pass # in api.py
data = { "text": args.text, "references": [ ServeReferenceAudio(audio=ref_audio, text=ref_text) for ref_text, ref_audio in zip(ref_texts, byte_audios) ], "reference_id": idstr, "normalize": args.normalize, "format": args.format, "mp3_bitrate": args.mp3_bitrate, "opus_bitrate": args.opus_bitrate, "max_new_tokens": args.max_new_tokens, "chunk_length": args.chunk_length, "top_p": args.top_p, "repetition_penalty": args.repetition_penalty, "temperature": args.temperature, "speaker": args.speaker, "emotion": args.emotion, "streaming": args.streaming, }
pydantic_data = ServeTTSRequest(**data)
response = requests.post( args.url, data=ormsgpack.packb(pydantic_data, option=ormsgpack.OPT_SERIALIZE_PYDANTIC), stream=args.streaming, headers={ "authorization": "Bearer YOUR_API_KEY", "content-type": "application/msgpack", }, )
if response.status_code == 200: if args.streaming: p = pyaudio.PyAudio() audio_format = pyaudio.paInt16 # Assuming 16-bit PCM format stream = p.open( format=audio_format, channels=args.channels, rate=args.rate, output=True )
wf = wave.open(f"{args.output}.wav", "wb") wf.setnchannels(args.channels) wf.setsampwidth(p.get_sample_size(audio_format)) wf.setframerate(args.rate)
stream_stopped_flag = False
try: for chunk in response.iter_content(chunk_size=1024): if chunk: stream.write(chunk) wf.writeframesraw(chunk) else: if not stream_stopped_flag: stream.stop_stream() stream_stopped_flag = True finally: stream.close() p.terminate() wf.close() else: audio_content = response.content audio_path = f"{args.output}.{args.format}" with open(audio_path, "wb") as audio_file: audio_file.write(audio_content)
audio = AudioSegment.from_file(audio_path, format=args.format) if args.play: play(audio) print(f"Audio has been saved to '{audio_path}'.") else: print(f"Request failed with status code {response.status_code}") print(response.json())1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859# FunASR Command Line Interface
This tool provides a command-line interface for separating vocals from instrumental tracks, converting videos to audio, and performing speech-to-text transcription on the resulting audio files.
## Requirements
- Python >= 3.10- PyTorch <= 2.3.1- ffmpeg, pydub, audio-separator[gpu].
## Installation
Install the required packages:
```bashpip install -e .[stable]```
Make sure you have `ffmpeg` installed and available in your `PATH`.
## Usage
### Basic Usage
To run the tool with default settings:
```bashpython tools/sensevoice/fun_asr.py --audio-dir <audio_directory> --save-dir <output_directory>```
## Options
| Option | Description || :-----------------------: | :---------------------------------------------------------------------------: || --audio-dir | Directory containing audio or video files. || --save-dir | Directory to save processed audio files. || --device | Device to use for processing. Options: cuda (default) or cpu. || --language | Language of the transcription. Default is auto. || --max_single_segment_time | Maximum duration of a single audio segment in milliseconds. Default is 20000. || --punc | Enable punctuation prediction. || --denoise | Enable noise reduction (vocal separation). |
## Example
To process audio files in the directory `path/to/audio` and save the output to `path/to/output`, with punctuation and noise reduction enabled:
```bashpython tools/sensevoice/fun_asr.py --audio-dir path/to/audio --save-dir path/to/output --punc --denoise```
## Additional Notes
- The tool supports `both audio and video files`. Videos will be converted to audio automatically.- If the `--denoise` option is used, the tool will perform vocal separation to isolate the vocals from the instrumental tracks.- The script will automatically create necessary directories in the `--save-dir`.
## Troubleshooting
If you encounter any issues, make sure all dependencies are correctly installed and configured. For more detailed troubleshooting, refer to the documentation of each dependency.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573#!/usr/bin/env python3# -*- encoding: utf-8 -*-# Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights Reserved.# MIT License (https://opensource.org/licenses/MIT)
import copyimport jsonimport loggingimport os.pathimport randomimport reimport stringimport time
import numpy as npimport torchfrom funasr.download.download_model_from_hub import download_modelfrom funasr.download.file import download_from_urlfrom funasr.register import tablesfrom funasr.train_utils.load_pretrained_model import load_pretrained_modelfrom funasr.train_utils.set_all_random_seed import set_all_random_seedfrom funasr.utils import export_utils, miscfrom funasr.utils.load_utils import load_audio_text_image_video, load_bytesfrom funasr.utils.misc import deep_updatefrom funasr.utils.timestamp_tools import timestamp_sentence, timestamp_sentence_enfrom tqdm import tqdm
from .vad_utils import merge_vad, slice_padding_audio_samples
try: from funasr.models.campplus.cluster_backend import ClusterBackend from funasr.models.campplus.utils import distribute_spk, postprocess, sv_chunkexcept: pass
def prepare_data_iterator(data_in, input_len=None, data_type=None, key=None): """ """ data_list = [] key_list = [] filelist = [".scp", ".txt", ".json", ".jsonl", ".text"]
chars = string.ascii_letters + string.digits if isinstance(data_in, str): if data_in.startswith("http://") or data_in.startswith("https://"): # url data_in = download_from_url(data_in)
if isinstance(data_in, str) and os.path.exists( data_in ): # wav_path; filelist: wav.scp, file.jsonl;text.txt; _, file_extension = os.path.splitext(data_in) file_extension = file_extension.lower() if file_extension in filelist: # filelist: wav.scp, file.jsonl;text.txt; with open(data_in, encoding="utf-8") as fin: for line in fin: key = "rand_key_" + "".join(random.choice(chars) for _ in range(13)) if data_in.endswith( ".jsonl" ): # file.jsonl: json.dumps({"source": data}) lines = json.loads(line.strip()) data = lines["source"] key = data["key"] if "key" in data else key else: # filelist, wav.scp, text.txt: id \t data or data lines = line.strip().split(maxsplit=1) data = lines[1] if len(lines) > 1 else lines[0] key = lines[0] if len(lines) > 1 else key
data_list.append(data) key_list.append(key) else: if key is None: # key = "rand_key_" + "".join(random.choice(chars) for _ in range(13)) key = misc.extract_filename_without_extension(data_in) data_list = [data_in] key_list = [key] elif isinstance(data_in, (list, tuple)): if data_type is not None and isinstance( data_type, (list, tuple) ): # mutiple inputs data_list_tmp = [] for data_in_i, data_type_i in zip(data_in, data_type): key_list, data_list_i = prepare_data_iterator( data_in=data_in_i, data_type=data_type_i ) data_list_tmp.append(data_list_i) data_list = [] for item in zip(*data_list_tmp): data_list.append(item) else: # [audio sample point, fbank, text] data_list = data_in key_list = [] for data_i in data_in: if isinstance(data_i, str) and os.path.exists(data_i): key = misc.extract_filename_without_extension(data_i) else: if key is None: key = "rand_key_" + "".join( random.choice(chars) for _ in range(13) ) key_list.append(key)
else: # raw text; audio sample point, fbank; bytes if isinstance(data_in, bytes): # audio bytes data_in = load_bytes(data_in) if key is None: key = "rand_key_" + "".join(random.choice(chars) for _ in range(13)) data_list = [data_in] key_list = [key]
return key_list, data_list
class AutoModel:
def __init__(self, **kwargs):
try: from funasr.utils.version_checker import check_for_update
print( "Check update of funasr, and it would cost few times. You may disable it by set `disable_update=True` in AutoModel" ) check_for_update(disable=kwargs.get("disable_update", False)) except: pass
log_level = getattr(logging, kwargs.get("log_level", "INFO").upper()) logging.basicConfig(level=log_level)
model, kwargs = self.build_model(**kwargs)
# if vad_model is not None, build vad model else None vad_model = kwargs.get("vad_model", None) vad_kwargs = ( {} if kwargs.get("vad_kwargs", {}) is None else kwargs.get("vad_kwargs", {}) ) if vad_model is not None: logging.info("Building VAD model.") vad_kwargs["model"] = vad_model vad_kwargs["model_revision"] = kwargs.get("vad_model_revision", "master") vad_kwargs["device"] = kwargs["device"] vad_model, vad_kwargs = self.build_model(**vad_kwargs)
# if punc_model is not None, build punc model else None punc_model = kwargs.get("punc_model", None) punc_kwargs = ( {} if kwargs.get("punc_kwargs", {}) is None else kwargs.get("punc_kwargs", {}) ) if punc_model is not None: logging.info("Building punc model.") punc_kwargs["model"] = punc_model punc_kwargs["model_revision"] = kwargs.get("punc_model_revision", "master") punc_kwargs["device"] = kwargs["device"] punc_model, punc_kwargs = self.build_model(**punc_kwargs)
# if spk_model is not None, build spk model else None spk_model = kwargs.get("spk_model", None) spk_kwargs = ( {} if kwargs.get("spk_kwargs", {}) is None else kwargs.get("spk_kwargs", {}) ) if spk_model is not None: logging.info("Building SPK model.") spk_kwargs["model"] = spk_model spk_kwargs["model_revision"] = kwargs.get("spk_model_revision", "master") spk_kwargs["device"] = kwargs["device"] spk_model, spk_kwargs = self.build_model(**spk_kwargs) self.cb_model = ClusterBackend().to(kwargs["device"]) spk_mode = kwargs.get("spk_mode", "punc_segment") if spk_mode not in ["default", "vad_segment", "punc_segment"]: logging.error( "spk_mode should be one of default, vad_segment and punc_segment." ) self.spk_mode = spk_mode
self.kwargs = kwargs self.model = model self.vad_model = vad_model self.vad_kwargs = vad_kwargs self.punc_model = punc_model self.punc_kwargs = punc_kwargs self.spk_model = spk_model self.spk_kwargs = spk_kwargs self.model_path = kwargs.get("model_path")
@staticmethod def build_model(**kwargs): assert "model" in kwargs if "model_conf" not in kwargs: logging.info( "download models from model hub: {}".format(kwargs.get("hub", "ms")) ) kwargs = download_model(**kwargs)
set_all_random_seed(kwargs.get("seed", 0))
device = kwargs.get("device", "cuda") if not torch.cuda.is_available() or kwargs.get("ngpu", 1) == 0: device = "cpu" kwargs["batch_size"] = 1 kwargs["device"] = device
torch.set_num_threads(kwargs.get("ncpu", 4))
# build tokenizer tokenizer = kwargs.get("tokenizer", None) if tokenizer is not None: tokenizer_class = tables.tokenizer_classes.get(tokenizer) tokenizer = tokenizer_class(**kwargs.get("tokenizer_conf", {})) kwargs["token_list"] = ( tokenizer.token_list if hasattr(tokenizer, "token_list") else None ) kwargs["token_list"] = ( tokenizer.get_vocab() if hasattr(tokenizer, "get_vocab") else kwargs["token_list"] ) vocab_size = ( len(kwargs["token_list"]) if kwargs["token_list"] is not None else -1 ) if vocab_size == -1 and hasattr(tokenizer, "get_vocab_size"): vocab_size = tokenizer.get_vocab_size() else: vocab_size = -1 kwargs["tokenizer"] = tokenizer
# build frontend frontend = kwargs.get("frontend", None) kwargs["input_size"] = None if frontend is not None: frontend_class = tables.frontend_classes.get(frontend) frontend = frontend_class(**kwargs.get("frontend_conf", {})) kwargs["input_size"] = ( frontend.output_size() if hasattr(frontend, "output_size") else None ) kwargs["frontend"] = frontend # build model model_class = tables.model_classes.get(kwargs["model"]) assert model_class is not None, f'{kwargs["model"]} is not registered' model_conf = {} deep_update(model_conf, kwargs.get("model_conf", {})) deep_update(model_conf, kwargs) model = model_class(**model_conf, vocab_size=vocab_size)
# init_param init_param = kwargs.get("init_param", None) if init_param is not None: if os.path.exists(init_param): logging.info(f"Loading pretrained params from {init_param}") load_pretrained_model( model=model, path=init_param, ignore_init_mismatch=kwargs.get("ignore_init_mismatch", True), oss_bucket=kwargs.get("oss_bucket", None), scope_map=kwargs.get("scope_map", []), excludes=kwargs.get("excludes", None), ) else: print(f"error, init_param does not exist!: {init_param}")
# fp16 if kwargs.get("fp16", False): model.to(torch.float16) elif kwargs.get("bf16", False): model.to(torch.bfloat16) model.to(device)
if not kwargs.get("disable_log", True): tables.print()
return model, kwargs
def __call__(self, *args, **cfg): kwargs = self.kwargs deep_update(kwargs, cfg) res = self.model(*args, kwargs) return res
def generate(self, input, input_len=None, **cfg): if self.vad_model is None: return self.inference(input, input_len=input_len, **cfg)
else: return self.inference_with_vad(input, input_len=input_len, **cfg)
def inference( self, input, input_len=None, model=None, kwargs=None, key=None, **cfg ): kwargs = self.kwargs if kwargs is None else kwargs if "cache" in kwargs: kwargs.pop("cache") deep_update(kwargs, cfg) model = self.model if model is None else model model.eval()
batch_size = kwargs.get("batch_size", 1) # if kwargs.get("device", "cpu") == "cpu": # batch_size = 1
key_list, data_list = prepare_data_iterator( input, input_len=input_len, data_type=kwargs.get("data_type", None), key=key )
speed_stats = {} asr_result_list = [] num_samples = len(data_list) disable_pbar = self.kwargs.get("disable_pbar", False) pbar = ( tqdm(colour="blue", total=num_samples, dynamic_ncols=True) if not disable_pbar else None ) time_speech_total = 0.0 time_escape_total = 0.0 for beg_idx in range(0, num_samples, batch_size): end_idx = min(num_samples, beg_idx + batch_size) data_batch = data_list[beg_idx:end_idx] key_batch = key_list[beg_idx:end_idx] batch = {"data_in": data_batch, "key": key_batch}
if (end_idx - beg_idx) == 1 and kwargs.get( "data_type", None ) == "fbank": # fbank batch["data_in"] = data_batch[0] batch["data_lengths"] = input_len
time1 = time.perf_counter() with torch.no_grad(): res = model.inference(**batch, **kwargs) if isinstance(res, (list, tuple)): results = res[0] if len(res) > 0 else [{"text": ""}] meta_data = res[1] if len(res) > 1 else {} time2 = time.perf_counter()
asr_result_list.extend(results)
# batch_data_time = time_per_frame_s * data_batch_i["speech_lengths"].sum().item() batch_data_time = meta_data.get("batch_data_time", -1) time_escape = time2 - time1 speed_stats["load_data"] = meta_data.get("load_data", 0.0) speed_stats["extract_feat"] = meta_data.get("extract_feat", 0.0) speed_stats["forward"] = f"{time_escape:0.3f}" speed_stats["batch_size"] = f"{len(results)}" speed_stats["rtf"] = f"{(time_escape) / batch_data_time:0.3f}" description = f"{speed_stats}, " if pbar: pbar.update(end_idx - beg_idx) pbar.set_description(description) time_speech_total += batch_data_time time_escape_total += time_escape
if pbar: # pbar.update(1) pbar.set_description(f"rtf_avg: {time_escape_total/time_speech_total:0.3f}") torch.cuda.empty_cache() return asr_result_list
def vad(self, input, input_len=None, **cfg): kwargs = self.kwargs # step.1: compute the vad model deep_update(self.vad_kwargs, cfg) beg_vad = time.time() res = self.inference( input, input_len=input_len, model=self.vad_model, kwargs=self.vad_kwargs, **cfg, ) end_vad = time.time() # FIX(gcf): concat the vad clips for sense vocie model for better aed if cfg.get("merge_vad", False): for i in range(len(res)): res[i]["value"] = merge_vad( res[i]["value"], kwargs.get("merge_length_s", 15) * 1000 ) elapsed = end_vad - beg_vad return elapsed, res
def inference_with_vadres(self, input, vad_res, input_len=None, **cfg):
kwargs = self.kwargs
# step.2 compute asr model model = self.model deep_update(kwargs, cfg) batch_size = max(int(kwargs.get("batch_size_s", 300)) * 1000, 1) batch_size_threshold_ms = int(kwargs.get("batch_size_threshold_s", 60)) * 1000 kwargs["batch_size"] = batch_size
key_list, data_list = prepare_data_iterator( input, input_len=input_len, data_type=kwargs.get("data_type", None) ) results_ret_list = [] time_speech_total_all_samples = 1e-6
beg_total = time.time() pbar_total = ( tqdm(colour="red", total=len(vad_res), dynamic_ncols=True) if not kwargs.get("disable_pbar", False) else None )
for i in range(len(vad_res)): key = vad_res[i]["key"] vadsegments = vad_res[i]["value"] input_i = data_list[i] fs = kwargs["frontend"].fs if hasattr(kwargs["frontend"], "fs") else 16000 speech = load_audio_text_image_video( input_i, fs=fs, audio_fs=kwargs.get("fs", 16000) ) speech_lengths = len(speech) n = len(vadsegments) data_with_index = [(vadsegments[i], i) for i in range(n)] sorted_data = sorted(data_with_index, key=lambda x: x[0][1] - x[0][0]) results_sorted = []
if not len(sorted_data): results_ret_list.append({"key": key, "text": "", "timestamp": []}) logging.info("decoding, utt: {}, empty speech".format(key)) continue
if len(sorted_data) > 0 and len(sorted_data[0]) > 0: batch_size = max( batch_size, sorted_data[0][0][1] - sorted_data[0][0][0] )
if kwargs["device"] == "cpu": batch_size = 0
beg_idx = 0 beg_asr_total = time.time() time_speech_total_per_sample = speech_lengths / 16000 time_speech_total_all_samples += time_speech_total_per_sample
# pbar_sample = tqdm(colour="blue", total=n, dynamic_ncols=True)
all_segments = [] max_len_in_batch = 0 end_idx = 1
for j, _ in enumerate(range(0, n)): # pbar_sample.update(1) sample_length = sorted_data[j][0][1] - sorted_data[j][0][0] potential_batch_length = max(max_len_in_batch, sample_length) * ( j + 1 - beg_idx ) # batch_size_ms_cum += sorted_data[j][0][1] - sorted_data[j][0][0] if ( j < n - 1 and sample_length < batch_size_threshold_ms and potential_batch_length < batch_size ): max_len_in_batch = max(max_len_in_batch, sample_length) end_idx += 1 continue
speech_j, speech_lengths_j, intervals = slice_padding_audio_samples( speech, speech_lengths, sorted_data[beg_idx:end_idx] ) results = self.inference( speech_j, input_len=None, model=model, kwargs=kwargs, **cfg )
for _b in range(len(speech_j)): results[_b]["interval"] = intervals[_b]
if self.spk_model is not None: # compose vad segments: [[start_time_sec, end_time_sec, speech], [...]] for _b in range(len(speech_j)): vad_segments = [ [ sorted_data[beg_idx:end_idx][_b][0][0] / 1000.0, sorted_data[beg_idx:end_idx][_b][0][1] / 1000.0, np.array(speech_j[_b]), ] ] segments = sv_chunk(vad_segments) all_segments.extend(segments) speech_b = [i[2] for i in segments] spk_res = self.inference( speech_b, input_len=None, model=self.spk_model, kwargs=kwargs, **cfg, ) results[_b]["spk_embedding"] = spk_res[0]["spk_embedding"]
beg_idx = end_idx end_idx += 1 max_len_in_batch = sample_length if len(results) < 1: continue results_sorted.extend(results)
# end_asr_total = time.time() # time_escape_total_per_sample = end_asr_total - beg_asr_total # pbar_sample.update(1) # pbar_sample.set_description(f"rtf_avg_per_sample: {time_escape_total_per_sample / time_speech_total_per_sample:0.3f}, " # f"time_speech_total_per_sample: {time_speech_total_per_sample: 0.3f}, " # f"time_escape_total_per_sample: {time_escape_total_per_sample:0.3f}")
restored_data = [0] * n for j in range(n): index = sorted_data[j][1] cur = results_sorted[j] pattern = r"<\|([^|]+)\|>" emotion_string = re.findall(pattern, cur["text"]) cur["text"] = re.sub(pattern, "", cur["text"]) cur["emo"] = "".join([f"<|{t}|>" for t in emotion_string]) if self.punc_model is not None and len(cur["text"].strip()) > 0: deep_update(self.punc_kwargs, cfg) punc_res = self.inference( cur["text"], model=self.punc_model, kwargs=self.punc_kwargs, **cfg, ) cur["text"] = punc_res[0]["text"]
restored_data[index] = cur
end_asr_total = time.time() time_escape_total_per_sample = end_asr_total - beg_asr_total if pbar_total: pbar_total.update(1) pbar_total.set_description( f"rtf_avg: {time_escape_total_per_sample / time_speech_total_per_sample:0.3f}, " f"time_speech: {time_speech_total_per_sample: 0.3f}, " f"time_escape: {time_escape_total_per_sample:0.3f}" )
# end_total = time.time() # time_escape_total_all_samples = end_total - beg_total # print(f"rtf_avg_all: {time_escape_total_all_samples / time_speech_total_all_samples:0.3f}, " # f"time_speech_all: {time_speech_total_all_samples: 0.3f}, " # f"time_escape_all: {time_escape_total_all_samples:0.3f}") return restored_data
def export(self, input=None, **cfg): """
:param input: :param type: :param quantize: :param fallback_num: :param calib_num: :param opset_version: :param cfg: :return: """
device = cfg.get("device", "cpu") model = self.model.to(device=device) kwargs = self.kwargs deep_update(kwargs, cfg) kwargs["device"] = device del kwargs["model"] model.eval()
type = kwargs.get("type", "onnx")
key_list, data_list = prepare_data_iterator( input, input_len=None, data_type=kwargs.get("data_type", None), key=None )
with torch.no_grad(): export_dir = export_utils.export(model=model, data_in=data_list, **kwargs)
return export_dir123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332import gcimport osimport re
from audio_separator.separator import Separator
os.environ["MODELSCOPE_CACHE"] = "./.cache/funasr"os.environ["UVR5_CACHE"] = "./.cache/uvr5-models"import jsonimport subprocessfrom pathlib import Path
import clickimport torchfrom loguru import loggerfrom pydub import AudioSegmentfrom silero_vad import get_speech_timestamps, load_silero_vad, read_audiofrom tqdm import tqdm
from tools.file import AUDIO_EXTENSIONS, VIDEO_EXTENSIONS, list_filesfrom tools.sensevoice.auto_model import AutoModel
def uvr5_cli( audio_dir: Path, output_folder: Path, audio_files: list[Path] | None = None, output_format: str = "flac", model: str = "BS-Roformer-Viperx-1297.ckpt",): # ["BS-Roformer-Viperx-1297.ckpt", "BS-Roformer-Viperx-1296.ckpt", "BS-Roformer-Viperx-1053.ckpt", "Mel-Roformer-Viperx-1143.ckpt"] sepr = Separator( model_file_dir=os.environ["UVR5_CACHE"], output_dir=output_folder, output_format=output_format, ) dictmodel = { "BS-Roformer-Viperx-1297.ckpt": "model_bs_roformer_ep_317_sdr_12.9755.ckpt", "BS-Roformer-Viperx-1296.ckpt": "model_bs_roformer_ep_368_sdr_12.9628.ckpt", "BS-Roformer-Viperx-1053.ckpt": "model_bs_roformer_ep_937_sdr_10.5309.ckpt", "Mel-Roformer-Viperx-1143.ckpt": "model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt", } roformer_model = dictmodel[model] sepr.load_model(roformer_model) if audio_files is None: audio_files = list_files( path=audio_dir, extensions=AUDIO_EXTENSIONS, recursive=True ) total_files = len(audio_files)
print(f"{total_files} audio files found")
res = [] for audio in tqdm(audio_files, desc="Denoising: "): file_path = str(audio_dir / audio) sep_out = sepr.separate(file_path) if isinstance(sep_out, str): res.append(sep_out) elif isinstance(sep_out, list): res.extend(sep_out) del sepr gc.collect() if torch.cuda.is_available(): torch.cuda.empty_cache()
return res, roformer_model
def get_sample_rate(media_path: Path): result = subprocess.run( [ "ffprobe", "-v", "quiet", "-print_format", "json", "-show_streams", str(media_path), ], capture_output=True, text=True, check=True, ) media_info = json.loads(result.stdout) for stream in media_info.get("streams", []): if stream.get("codec_type") == "audio": return stream.get("sample_rate") return "44100" # Default sample rate if not found
def convert_to_mono(src_path: Path, out_path: Path, out_fmt: str = "wav"): sr = get_sample_rate(src_path) out_path.parent.mkdir(parents=True, exist_ok=True) if src_path.resolve() == out_path.resolve(): output = str(out_path.with_stem(out_path.stem + f"_{sr}")) else: output = str(out_path) subprocess.run( [ "ffmpeg", "-loglevel", "error", "-i", str(src_path), "-acodec", "pcm_s16le" if out_fmt == "wav" else "flac", "-ar", sr, "-ac", "1", "-y", output, ], check=True, ) return out_path
def convert_video_to_audio(video_path: Path, audio_dir: Path): cur_dir = audio_dir / video_path.relative_to(audio_dir).parent vocals = [ p for p in cur_dir.glob(f"{video_path.stem}_(Vocals)*.*") if p.suffix in AUDIO_EXTENSIONS ] if len(vocals) > 0: return vocals[0] audio_path = cur_dir / f"{video_path.stem}.wav" convert_to_mono(video_path, audio_path) return audio_path
@click.command()@click.option("--audio-dir", required=True, help="Directory containing audio files")@click.option( "--save-dir", required=True, help="Directory to save processed audio files")@click.option("--device", default="cuda", help="Device to use [cuda / cpu]")@click.option("--language", default="auto", help="Language of the transcription")@click.option( "--max_single_segment_time", default=20000, type=int, help="Maximum of Output single audio duration(ms)",)@click.option("--fsmn-vad/--silero-vad", default=False)@click.option("--punc/--no-punc", default=False)@click.option("--denoise/--no-denoise", default=False)@click.option("--save_emo/--no_save_emo", default=False)def main( audio_dir: str, save_dir: str, device: str, language: str, max_single_segment_time: int, fsmn_vad: bool, punc: bool, denoise: bool, save_emo: bool,):
audios_path = Path(audio_dir) save_path = Path(save_dir) save_path.mkdir(parents=True, exist_ok=True)
video_files = list_files( path=audio_dir, extensions=VIDEO_EXTENSIONS, recursive=True ) v2a_files = [convert_video_to_audio(p, audio_dir) for p in video_files]
if denoise: VOCAL = "_(Vocals)" original_files = [ p for p in audios_path.glob("**/*") if p.suffix in AUDIO_EXTENSIONS and VOCAL not in p.stem ]
_, cur_model = uvr5_cli( audio_dir=audio_dir, output_folder=audio_dir, audio_files=original_files ) need_remove = [p for p in audios_path.glob("**/*(Instrumental)*")] need_remove.extend(original_files) for _ in need_remove: _.unlink() vocal_files = [ p for p in audios_path.glob("**/*") if p.suffix in AUDIO_EXTENSIONS and VOCAL in p.stem ] for f in vocal_files: fn, ext = f.stem, f.suffix
v_pos = fn.find(VOCAL + "_" + cur_model.split(".")[0]) if v_pos != -1: new_fn = fn[: v_pos + len(VOCAL)] new_f = f.with_name(new_fn + ext) f = f.rename(new_f) convert_to_mono(f, f, "flac") f.unlink()
audio_files = list_files( path=audio_dir, extensions=AUDIO_EXTENSIONS, recursive=True )
logger.info("Loading / Downloading Funasr model...")
model_dir = "iic/SenseVoiceSmall"
vad_model = "fsmn-vad" if fsmn_vad else None vad_kwargs = {"max_single_segment_time": max_single_segment_time} punc_model = "ct-punc" if punc else None
manager = AutoModel( model=model_dir, trust_remote_code=False, vad_model=vad_model, vad_kwargs=vad_kwargs, punc_model=punc_model, device=device, )
if not fsmn_vad and vad_model is None: vad_model = load_silero_vad()
logger.info("Model loaded.")
pattern = re.compile(r"_\d{3}\.")
for file_path in tqdm(audio_files, desc="Processing audio file"):
if pattern.search(file_path.name): # logger.info(f"Skipping {file_path} as it has already been processed.") continue
file_stem = file_path.stem file_suffix = file_path.suffix
rel_path = Path(file_path).relative_to(audio_dir) (save_path / rel_path.parent).mkdir(parents=True, exist_ok=True)
audio = AudioSegment.from_file(file_path)
cfg = dict( cache={}, language=language, # "zh", "en", "yue", "ja", "ko", "nospeech" use_itn=False, batch_size_s=60, )
if fsmn_vad: elapsed, vad_res = manager.vad(input=str(file_path), **cfg) else: wav = read_audio( str(file_path) ) # backend (sox, soundfile, or ffmpeg) required! audio_key = file_path.stem audio_val = [] speech_timestamps = get_speech_timestamps( wav, vad_model, max_speech_duration_s=max_single_segment_time // 1000, return_seconds=True, )
audio_val = [ [int(timestamp["start"] * 1000), int(timestamp["end"] * 1000)] for timestamp in speech_timestamps ] vad_res = [] vad_res.append(dict(key=audio_key, value=audio_val))
res = manager.inference_with_vadres( input=str(file_path), vad_res=vad_res, **cfg )
for i, info in enumerate(res): [start_ms, end_ms] = info["interval"] text = info["text"] emo = info["emo"] sliced_audio = audio[start_ms:end_ms] audio_save_path = ( save_path / rel_path.parent / f"{file_stem}_{i:03d}{file_suffix}" ) sliced_audio.export(audio_save_path, format=file_suffix[1:]) print(f"Exported {audio_save_path}: {text}")
transcript_save_path = ( save_path / rel_path.parent / f"{file_stem}_{i:03d}.lab" ) with open( transcript_save_path, "w", encoding="utf-8", ) as f: f.write(text)
if save_emo: emo_save_path = save_path / rel_path.parent / f"{file_stem}_{i:03d}.emo" with open( emo_save_path, "w", encoding="utf-8", ) as f: f.write(emo)
if audios_path.resolve() == save_path.resolve(): file_path.unlink()
if __name__ == "__main__": main() exit(0) from funasr.utils.postprocess_utils import rich_transcription_postprocess
# Load the audio file audio_path = Path(r"D:\PythonProject\ok\1_output_(Vocals).wav") model_dir = "iic/SenseVoiceSmall" m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0") m.eval()
res = m.inference( data_in=f"{kwargs['model_path']}/example/zh.mp3", language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech" use_itn=False, ban_emo_unk=False, **kwargs, )
print(res) text = rich_transcription_postprocess(res[0][0]["text"]) print(text)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import torchfrom torch.nn.utils.rnn import pad_sequence
def slice_padding_fbank(speech, speech_lengths, vad_segments): speech_list = [] speech_lengths_list = [] for i, segment in enumerate(vad_segments):
bed_idx = int(segment[0][0] * 16) end_idx = min(int(segment[0][1] * 16), speech_lengths[0]) speech_i = speech[0, bed_idx:end_idx] speech_lengths_i = end_idx - bed_idx speech_list.append(speech_i) speech_lengths_list.append(speech_lengths_i) feats_pad = pad_sequence(speech_list, batch_first=True, padding_value=0.0) speech_lengths_pad = torch.Tensor(speech_lengths_list).int() return feats_pad, speech_lengths_pad
def slice_padding_audio_samples(speech, speech_lengths, vad_segments): speech_list = [] speech_lengths_list = [] intervals = [] for i, segment in enumerate(vad_segments): bed_idx = int(segment[0][0] * 16) end_idx = min(int(segment[0][1] * 16), speech_lengths) speech_i = speech[bed_idx:end_idx] speech_lengths_i = end_idx - bed_idx speech_list.append(speech_i) speech_lengths_list.append(speech_lengths_i) intervals.append([bed_idx // 16, end_idx // 16])
return speech_list, speech_lengths_list, intervals
def merge_vad(vad_result, max_length=15000, min_length=0): new_result = [] if len(vad_result) <= 1: return vad_result time_step = [t[0] for t in vad_result] + [t[1] for t in vad_result] time_step = sorted(list(set(time_step))) if len(time_step) == 0: return [] bg = 0 for i in range(len(time_step) - 1): time = time_step[i] if time_step[i + 1] - bg < max_length: continue if time - bg > min_length: new_result.append([bg, time]) # if time - bg < max_length * 1.5: # new_result.append([bg, time]) # else: # split_num = int(time - bg) // max_length + 1 # spl_l = int(time - bg) // split_num # for j in range(split_num): # new_result.append([bg + j * spl_l, bg + (j + 1) * spl_l]) bg = time new_result.append([bg, time_step[-1]]) return new_result1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import randomfrom multiprocessing import Poolfrom pathlib import Path
import clickimport librosaimport torch.nn.functional as Fimport torchaudiofrom tqdm import tqdm
from tools.file import AUDIO_EXTENSIONS, list_files
threshold = 10 ** (-50 / 20.0)
def process(file): waveform, sample_rate = torchaudio.load(str(file), backend="sox") loudness = librosa.feature.rms( y=waveform.numpy().squeeze(), frame_length=2048, hop_length=512, center=True )[0] for i in range(len(loudness) - 1, 0, -1): if loudness[i] > threshold: break
silent_time = (len(loudness) - i) * 512 / sample_rate
if silent_time <= 0.3: random_time = random.uniform(0.3, 0.7) waveform = F.pad( waveform, (0, int(random_time * sample_rate)), mode="constant", value=0 )
torchaudio.save(uri=str(file), src=waveform, sample_rate=sample_rate)
@click.command()@click.argument("source", type=Path)@click.option("--num-workers", type=int, default=12)def main(source, num_workers): files = list(list_files(source, AUDIO_EXTENSIONS, recursive=True))
with Pool(num_workers) as p: list(tqdm(p.imap_unordered(process, files), total=len(files)))
if __name__ == "__main__": main()6 unmodified lines789101112136 unmodified linesfrom pydub import AudioSegmentfrom tqdm import tqdmfrom fish_speech.utils.file import AUDIO_EXTENSIONS, list_files, load_filelist@click.command()6 unmodified lines789101112136 unmodified linesfrom pydub import AudioSegmentfrom tqdm import tqdmfrom tools.file import AUDIO_EXTENSIONS, list_files, load_filelist@click.command()
16 unmodified lines1718192021222318 unmodified lines4243444546474884 unmodified lines13313413513613713813916 unmodified linesfrom loguru import loggerfrom omegaconf import OmegaConffrom fish_speech.utils.file import AUDIO_EXTENSIONS, list_files, load_filelist# register eval resolverOmegaConf.register_new_resolver("eval", eval)18 unmodified lines@lru_cache(maxsize=1)def get_model(config_name: str = "firefly_gan_vq",checkpoint_path: str = "checkpoints/fish-speech-1.2-sft/firefly-gan-vq-fsq-4x1024-42hz-generator.pth",device: str | torch.device = "cuda",):with initialize(version_base="1.3", config_path="../../fish_speech/configs"):84 unmodified lines@click.option("--config-name", default="firefly_gan_vq")@click.option("--checkpoint-path",default="checkpoints/fish-speech-1.2-sft/firefly-gan-vq-fsq-4x1024-42hz-generator.pth",)@click.option("--batch-size", default=64)@click.option("--filelist", default=None, type=Path)16 unmodified lines1718192021222318 unmodified lines4243444546474884 unmodified lines13313413513613713813916 unmodified linesfrom loguru import loggerfrom omegaconf import OmegaConffrom tools.file import AUDIO_EXTENSIONS, list_files, load_filelist# register eval resolverOmegaConf.register_new_resolver("eval", eval)18 unmodified lines@lru_cache(maxsize=1)def get_model(config_name: str = "firefly_gan_vq",checkpoint_path: str = "checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth",device: str | torch.device = "cuda",):with initialize(version_base="1.3", config_path="../../fish_speech/configs"):84 unmodified lines@click.option("--config-name", default="firefly_gan_vq")@click.option("--checkpoint-path",default="checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth",)@click.option("--batch-size", default=64)@click.option("--filelist", default=None, type=Path)
10 unmodified lines1112131415161741 unmodified lines5960616263646537 unmodified lines10310410510610710810910 unmodified linesfrom loguru import loggerfrom omegaconf import OmegaConffrom fish_speech.utils.file import AUDIO_EXTENSIONS# register eval resolverOmegaConf.register_new_resolver("eval", eval)41 unmodified lines@click.option("--config-name", default="firefly_gan_vq")@click.option("--checkpoint-path",default="checkpoints/fish-speech-1.2-sft/firefly-gan-vq-fsq-4x1024-42hz-generator.pth",)@click.option("--device",37 unmodified lines# Restorefeature_lengths = torch.tensor([indices.shape[1]], device=device)fake_audios = model.decode(indices=indices[None], feature_lengths=feature_lengths)audio_time = fake_audios.shape[-1] / model.spec_transform.sample_ratelogger.info(10 unmodified lines1112131415161741 unmodified lines5960616263646537 unmodified lines10310410510610710810911011110 unmodified linesfrom loguru import loggerfrom omegaconf import OmegaConffrom tools.file import AUDIO_EXTENSIONS# register eval resolverOmegaConf.register_new_resolver("eval", eval)41 unmodified lines@click.option("--config-name", default="firefly_gan_vq")@click.option("--checkpoint-path",default="checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth",)@click.option("--device",37 unmodified lines# Restorefeature_lengths = torch.tensor([indices.shape[1]], device=device)fake_audios, _ = model.decode(indices=indices[None], feature_lengths=feature_lengths)audio_time = fake_audios.shape[-1] / model.spec_transform.sample_ratelogger.info(
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619import gcimport htmlimport ioimport osimport queueimport wavefrom argparse import ArgumentParserfrom functools import partialfrom pathlib import Path
import gradio as grimport librosaimport numpy as npimport pyrootutilsimport torchfrom loguru import loggerfrom transformers import AutoTokenizer
pyrootutils.setup_root(__file__, indicator=".project-root", pythonpath=True)
from fish_speech.i18n import i18nfrom fish_speech.text.chn_text_norm.text import Text as ChnNormedTextfrom fish_speech.utils import autocast_exclude_mpsfrom tools.api import decode_vq_tokens, encode_referencefrom tools.auto_rerank import batch_asr, calculate_wer, is_chinese, load_modelfrom tools.llama.generate import ( GenerateRequest, GenerateResponse, WrappedGenerateResponse, launch_thread_safe_queue,)from tools.vqgan.inference import load_model as load_decoder_model
# Make einx happyos.environ["EINX_FILTER_TRACEBACK"] = "false"
HEADER_MD = f"""# Fish Speech
{i18n("A text-to-speech model based on VQ-GAN and Llama developed by [Fish Audio](https://fish.audio).")}
{i18n("You can find the source code [here](https://github.com/fishaudio/fish-speech) and models [here](https://huggingface.co/fishaudio/fish-speech-1.4).")}
{i18n("Related code and weights are released under CC BY-NC-SA 4.0 License.")}
{i18n("We are not responsible for any misuse of the model, please consider your local laws and regulations before using it.")} """
TEXTBOX_PLACEHOLDER = i18n("Put your text here.")SPACE_IMPORTED = False
def build_html_error_message(error): return f""" <div style="color: red; font-weight: bold;"> {html.escape(str(error))} </div> """
@torch.inference_mode()def inference( text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, streaming=False,): if args.max_gradio_length > 0 and len(text) > args.max_gradio_length: return ( None, None, i18n("Text is too long, please keep it under {} characters.").format( args.max_gradio_length ), )
# Parse reference audio aka prompt prompt_tokens = encode_reference( decoder_model=decoder_model, reference_audio=reference_audio, enable_reference_audio=enable_reference_audio, )
# LLAMA Inference request = dict( device=decoder_model.device, max_new_tokens=max_new_tokens, text=text, top_p=top_p, repetition_penalty=repetition_penalty, temperature=temperature, compile=args.compile, iterative_prompt=chunk_length > 0, chunk_length=chunk_length, max_length=2048, prompt_tokens=prompt_tokens if enable_reference_audio else None, prompt_text=reference_text if enable_reference_audio else None, )
response_queue = queue.Queue() llama_queue.put( GenerateRequest( request=request, response_queue=response_queue, ) )
if streaming: yield wav_chunk_header(), None, None
segments = []
while True: result: WrappedGenerateResponse = response_queue.get() if result.status == "error": yield None, None, build_html_error_message(result.response) break
result: GenerateResponse = result.response if result.action == "next": break
with autocast_exclude_mps( device_type=decoder_model.device.type, dtype=args.precision ): fake_audios = decode_vq_tokens( decoder_model=decoder_model, codes=result.codes, )
fake_audios = fake_audios.float().cpu().numpy() segments.append(fake_audios)
if streaming: yield (fake_audios * 32768).astype(np.int16).tobytes(), None, None
if len(segments) == 0: return ( None, None, build_html_error_message( i18n("No audio generated, please check the input text.") ), )
# No matter streaming or not, we need to return the final audio audio = np.concatenate(segments, axis=0) yield None, (decoder_model.spec_transform.sample_rate, audio), None
if torch.cuda.is_available(): torch.cuda.empty_cache() gc.collect()
def inference_with_auto_rerank( text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, use_auto_rerank, streaming=False,):
max_attempts = 2 if use_auto_rerank else 1 best_wer = float("inf") best_audio = None best_sample_rate = None
for attempt in range(max_attempts): audio_generator = inference( text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, streaming=False, )
# 获取音频数据 for _ in audio_generator: pass _, (sample_rate, audio), message = _
if audio is None: return None, None, message
if not use_auto_rerank: return None, (sample_rate, audio), None
asr_result = batch_asr(asr_model, [audio], sample_rate)[0] wer = calculate_wer(text, asr_result["text"]) if wer <= 0.3 and not asr_result["huge_gap"]: return None, (sample_rate, audio), None
if wer < best_wer: best_wer = wer best_audio = audio best_sample_rate = sample_rate
if attempt == max_attempts - 1: break
return None, (best_sample_rate, best_audio), None
inference_stream = partial(inference, streaming=True)
n_audios = 4
global_audio_list = []global_error_list = []
def inference_wrapper( text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, batch_infer_num, if_load_asr_model,): audios = [] errors = []
for _ in range(batch_infer_num): result = inference_with_auto_rerank( text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, if_load_asr_model, )
_, audio_data, error_message = result
audios.append( gr.Audio(value=audio_data if audio_data else None, visible=True), ) errors.append( gr.HTML(value=error_message if error_message else None, visible=True), )
for _ in range(batch_infer_num, n_audios): audios.append( gr.Audio(value=None, visible=False), ) errors.append( gr.HTML(value=None, visible=False), )
return None, *audios, *errors
def wav_chunk_header(sample_rate=44100, bit_depth=16, channels=1): buffer = io.BytesIO()
with wave.open(buffer, "wb") as wav_file: wav_file.setnchannels(channels) wav_file.setsampwidth(bit_depth // 8) wav_file.setframerate(sample_rate)
wav_header_bytes = buffer.getvalue() buffer.close() return wav_header_bytes
def normalize_text(user_input, use_normalization): if use_normalization: return ChnNormedText(raw_text=user_input).normalize() else: return user_input
asr_model = None
def change_if_load_asr_model(if_load): global asr_model
if if_load: gr.Warning("Loading faster whisper model...") if asr_model is None: asr_model = load_model() return gr.Checkbox(label="Unload faster whisper model", value=if_load)
if if_load is False: gr.Warning("Unloading faster whisper model...") del asr_model asr_model = None if torch.cuda.is_available(): torch.cuda.empty_cache() gc.collect() return gr.Checkbox(label="Load faster whisper model", value=if_load)
def change_if_auto_label(if_load, if_auto_label, enable_ref, ref_audio, ref_text): if if_load and asr_model is not None: if ( if_auto_label and enable_ref and ref_audio is not None and ref_text.strip() == "" ): data, sample_rate = librosa.load(ref_audio) res = batch_asr(asr_model, [data], sample_rate)[0] ref_text = res["text"] else: gr.Warning("Whisper model not loaded!")
return gr.Textbox(value=ref_text)
def build_app(): with gr.Blocks(theme=gr.themes.Base()) as app: gr.Markdown(HEADER_MD)
# Use light theme by default app.load( None, None, js="() => {const params = new URLSearchParams(window.location.search);if (!params.has('__theme')) {params.set('__theme', '%s');window.location.search = params.toString();}}" % args.theme, )
# Inference with gr.Row(): with gr.Column(scale=3): text = gr.Textbox( label=i18n("Input Text"), placeholder=TEXTBOX_PLACEHOLDER, lines=10 ) refined_text = gr.Textbox( label=i18n("Realtime Transform Text"), placeholder=i18n( "Normalization Result Preview (Currently Only Chinese)" ), lines=5, interactive=False, )
with gr.Row(): if_refine_text = gr.Checkbox( label=i18n("Text Normalization"), value=False, scale=1, )
if_load_asr_model = gr.Checkbox( label=i18n("Load / Unload ASR model for auto-reranking"), value=False, scale=3, )
with gr.Row(): with gr.Tab(label=i18n("Advanced Config")): chunk_length = gr.Slider( label=i18n("Iterative Prompt Length, 0 means off"), minimum=50, maximum=300, value=200, step=8, )
max_new_tokens = gr.Slider( label=i18n("Maximum tokens per batch, 0 means no limit"), minimum=0, maximum=2048, value=1024, # 0 means no limit step=8, )
top_p = gr.Slider( label="Top-P", minimum=0.6, maximum=0.9, value=0.7, step=0.01, )
repetition_penalty = gr.Slider( label=i18n("Repetition Penalty"), minimum=1, maximum=1.5, value=1.2, step=0.01, )
temperature = gr.Slider( label="Temperature", minimum=0.6, maximum=0.9, value=0.7, step=0.01, )
with gr.Tab(label=i18n("Reference Audio")): gr.Markdown( i18n( "5 to 10 seconds of reference audio, useful for specifying speaker." ) )
enable_reference_audio = gr.Checkbox( label=i18n("Enable Reference Audio"), ) reference_audio = gr.Audio( label=i18n("Reference Audio"), type="filepath", ) with gr.Row(): if_auto_label = gr.Checkbox( label=i18n("Auto Labeling"), min_width=100, scale=0, value=False, ) reference_text = gr.Textbox( label=i18n("Reference Text"), lines=1, placeholder="在一无所知中,梦里的一天结束了,一个新的「轮回」便会开始。", value="", ) with gr.Tab(label=i18n("Batch Inference")): batch_infer_num = gr.Slider( label="Batch infer nums", minimum=1, maximum=n_audios, step=1, value=1, )
with gr.Column(scale=3): for _ in range(n_audios): with gr.Row(): error = gr.HTML( label=i18n("Error Message"), visible=True if _ == 0 else False, ) global_error_list.append(error) with gr.Row(): audio = gr.Audio( label=i18n("Generated Audio"), type="numpy", interactive=False, visible=True if _ == 0 else False, ) global_audio_list.append(audio)
with gr.Row(): stream_audio = gr.Audio( label=i18n("Streaming Audio"), streaming=True, autoplay=True, interactive=False, show_download_button=True, ) with gr.Row(): with gr.Column(scale=3): generate = gr.Button( value="\U0001F3A7 " + i18n("Generate"), variant="primary" ) generate_stream = gr.Button( value="\U0001F3A7 " + i18n("Streaming Generate"), variant="primary", )
text.input( fn=normalize_text, inputs=[text, if_refine_text], outputs=[refined_text] )
if_load_asr_model.change( fn=change_if_load_asr_model, inputs=[if_load_asr_model], outputs=[if_load_asr_model], )
if_auto_label.change( fn=lambda: gr.Textbox(value=""), inputs=[], outputs=[reference_text], ).then( fn=change_if_auto_label, inputs=[ if_load_asr_model, if_auto_label, enable_reference_audio, reference_audio, reference_text, ], outputs=[reference_text], )
# # Submit generate.click( inference_wrapper, [ refined_text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, batch_infer_num, if_load_asr_model, ], [stream_audio, *global_audio_list, *global_error_list], concurrency_limit=1, )
generate_stream.click( inference_stream, [ refined_text, enable_reference_audio, reference_audio, reference_text, max_new_tokens, chunk_length, top_p, repetition_penalty, temperature, ], [stream_audio, global_audio_list[0], global_error_list[0]], concurrency_limit=10, ) return app
def parse_args(): parser = ArgumentParser() parser.add_argument( "--llama-checkpoint-path", type=Path, default="checkpoints/fish-speech-1.4", ) parser.add_argument( "--decoder-checkpoint-path", type=Path, default="checkpoints/fish-speech-1.4/firefly-gan-vq-fsq-8x1024-21hz-generator.pth", ) parser.add_argument("--decoder-config-name", type=str, default="firefly_gan_vq") parser.add_argument("--device", type=str, default="cuda") parser.add_argument("--half", action="store_true") parser.add_argument("--compile", action="store_true") parser.add_argument("--max-gradio-length", type=int, default=0) parser.add_argument("--theme", type=str, default="light")
return parser.parse_args()
if __name__ == "__main__": args = parse_args() args.precision = torch.half if args.half else torch.bfloat16
logger.info("Loading Llama model...") llama_queue = launch_thread_safe_queue( checkpoint_path=args.llama_checkpoint_path, device=args.device, precision=args.precision, compile=args.compile, ) logger.info("Llama model loaded, loading VQ-GAN model...")
decoder_model = load_decoder_model( config_name=args.decoder_config_name, checkpoint_path=args.decoder_checkpoint_path, device=args.device, )
logger.info("Decoder model loaded, warming up...")
# Dry run to check if the model is loaded correctly and avoid the first-time latency list( inference( text="Hello, world!", enable_reference_audio=False, reference_audio=None, reference_text="", max_new_tokens=0, chunk_length=100, top_p=0.7, repetition_penalty=1.2, temperature=0.7, ) )
logger.info("Warming up done, launching the web UI...")
app = build_app() app.launch(show_api=True)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176"""Used to transcribe all audio files in one folder into another folder.e.g.Directory structure:--pre_data_root----SP_1------01.wav------02.wav------......----SP_2------01.wav------02.wav------......Use python tools/whisper_asr.py --audio-dir pre_data_root/SP_1 --save-dir data/SP_1 to transcribe the first speaker.
Use python tools/whisper_asr.py --audio-dir pre_data_root/SP_2 --save-dir data/SP_2 to transcribe the second speaker.
Note: Be aware of your audio sample rate, which defaults to 44.1kHz."""
import refrom pathlib import Path
import clickimport soundfile as sffrom faster_whisper import WhisperModelfrom loguru import loggerfrom pydub import AudioSegmentfrom tqdm import tqdm
from tools.file import AUDIO_EXTENSIONS, list_files
@click.command()@click.option("--model-size", default="large-v3", help="Size of the Whisper model")@click.option( "--compute-type", default="float16", help="Computation Precision of the Whisper model [float16 / int8_float16 / int8]",)@click.option("--audio-dir", required=True, help="Directory containing audio files")@click.option( "--save-dir", required=True, help="Directory to save processed audio files")@click.option( "--sample-rate", default=44100, type=int, help="Output sample rate, default to input sample rate",)@click.option("--device", default="cuda", help="Device to use [cuda / cpu]")@click.option("--language", default="auto", help="Language of the transcription")@click.option("--initial-prompt", default=None, help="Initial prompt for transcribing")def main( model_size, compute_type, audio_dir, save_dir, sample_rate, device, language, initial_prompt,): logger.info("Loading / Downloading Faster Whisper model...")
model = WhisperModel( model_size, device=device, compute_type=compute_type, download_root="faster_whisper", )
logger.info("Model loaded.")
save_path = Path(save_dir) save_path.mkdir(parents=True, exist_ok=True)
audio_files = list_files( path=audio_dir, extensions=AUDIO_EXTENSIONS, recursive=True )
for file_path in tqdm(audio_files, desc="Processing audio file"): file_stem = file_path.stem file_suffix = file_path.suffix
rel_path = Path(file_path).relative_to(audio_dir) (save_path / rel_path.parent).mkdir(parents=True, exist_ok=True)
audio = AudioSegment.from_file(file_path)
segments, info = model.transcribe( file_path, beam_size=5, language=None if language == "auto" else language, initial_prompt=initial_prompt, )
print( "Detected language '%s' with probability %f" % (info.language, info.language_probability) ) print("Total len(ms): ", len(audio))
whole_text = None for segment in segments: id, start, end, text = ( segment.id, segment.start, segment.end, segment.text, ) print("Segment %03d [%.2fs -> %.2fs] %s" % (id, start, end, text)) if not whole_text: whole_text = text else: whole_text += ", " + text
whole_text += "."
audio_save_path = save_path / rel_path.parent / f"{file_stem}{file_suffix}" audio.export(audio_save_path, format=file_suffix[1:]) print(f"Exported {audio_save_path}")
transcript_save_path = save_path / rel_path.parent / f"{file_stem}.lab" with open( transcript_save_path, "w", encoding="utf-8", ) as f: f.write(whole_text)
if __name__ == "__main__": main() exit(0)
audio = AudioSegment.from_wav( r"D:\PythonProject\原神语音中文\胡桃\vo_hutao_draw_appear.wav" )
model_size = "large-v3"
model = WhisperModel( model_size, device="cuda", compute_type="float16", download_root="faster_whisper", )
segments, info = model.transcribe( r"D:\PythonProject\原神语音中文\胡桃\vo_hutao_draw_appear.wav", beam_size=5, )
print( "Detected language '%s' with probability %f" % (info.language, info.language_probability) ) print("Total len(ms): ", len(audio))
for i, segment in enumerate(segments): print( "Segment %03d [%.2fs -> %.2fs] %s" % (i, segment.start, segment.end, segment.text) ) start_ms = int(segment.start * 1000) end_ms = int(segment.end * 1000) segment_audio = audio[start_ms:end_ms] segment_audio.export(f"segment_{i:03d}.wav", format="wav") print(f"Exported segment_{i:03d}.wav")
print("All segments have been exported.")app.py+7-7
fish_speech/configs/firefly_gan_vq.yaml+2-3
fish_speech/configs/text2semantic_finetune.yaml+1-1
fish_speech/i18n/README.mdAdded+27
fish_speech/i18n/__init__.pyAdded+3
fish_speech/i18n/core.pyAdded+40
fish_speech/i18n/locale/en_US.jsonAdded+122
fish_speech/i18n/locale/es_ES.jsonAdded+122
fish_speech/i18n/locale/ja_JP.jsonAdded+123
fish_speech/i18n/locale/pt_BR.jsonAdded+133
fish_speech/i18n/locale/zh_CN.jsonAdded+122
fish_speech/i18n/scan.pyAdded+122
fish_speech/models/text2semantic/llama.py+27
fish_speech/models/vqgan/__init__.py-3
fish_speech/models/vqgan/modules/firefly.py+167-196
fish_speech/models/vqgan/modules/fsq.py+4-27
fish_speech/scheduler.py+19-1
fish_speech/text/clean.py+1-1
fish_speech/train.py+5-1
fish_speech/utils/__init__.py+2
fish_speech/utils/context.pyAdded+13
fish_speech/utils/file.py-103
fish_speech/webui/css/style.cssAdded+161
fish_speech/webui/html/footer.htmlAdded+11
fish_speech/webui/js/animate.jsAdded+69
fish_speech/webui/launch_utils.pyAdded+120
fish_speech/webui/manage.pyAdded+1237
requirements.txt+2-1
tools/api.py+93-135
tools/commons.pyAdded+35
tools/download_models.pyAdded+55
tools/extract_model.pyAdded+21
tools/file.pyAdded+125
tools/llama/build_dataset.py+1-1
tools/llama/generate.py+28-10
tools/llama/merge_lora.py+1-1
tools/llama/quantize.py+2-2
tools/msgpack_api.pyAdded+34
tools/post_api.pyAdded+205
tools/sensevoice/README.mdAdded+59
tools/sensevoice/__init__.pyAdded
tools/sensevoice/auto_model.pyAdded+573
tools/sensevoice/fun_asr.pyAdded+332
tools/sensevoice/vad_utils.pyAdded+61
tools/smart_pad.pyAdded+47
tools/vqgan/create_train_split.py+1-1
tools/vqgan/extract_vq.py+3-3
tools/vqgan/inference.py+5-3
tools/webui.pyAdded+619
tools/whisper_asr.pyAdded+176