jarvislk commited on
Commit
1bba990
·
1 Parent(s): 6a8366c

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .env +8 -0
  2. .github/PULL_REQUEST_TEMPLATE.md +30 -0
  3. .github/workflows/docker.yml +70 -0
  4. .github/workflows/genlocale.yml +33 -0
  5. .github/workflows/pull_format.yml +38 -0
  6. .github/workflows/push_format.yml +56 -0
  7. .github/workflows/unitest.yml +36 -0
  8. .gitignore +23 -0
  9. Dockerfile +29 -0
  10. GUI.py +1410 -0
  11. LICENSE +23 -0
  12. MIT协议暨相关引用库协议 +45 -0
  13. README.md +34 -8
  14. Retrieval_based_Voice_Conversion_WebUI.ipynb +403 -0
  15. Retrieval_based_Voice_Conversion_WebUI_v2.ipynb +422 -0
  16. a.png +0 -0
  17. app.py +1441 -0
  18. assets/hubert/.gitignore +2 -0
  19. assets/hubert/hubert_base.pt +3 -0
  20. assets/pretrained/.gitignore +2 -0
  21. assets/pretrained_v2/.gitignore +2 -0
  22. assets/pretrained_v2/D40k.pth +3 -0
  23. assets/pretrained_v2/G40k.pth +3 -0
  24. assets/pretrained_v2/f0D40k.pth +3 -0
  25. assets/pretrained_v2/f0G40k.pth +3 -0
  26. assets/rmvpe/.gitignore +2 -0
  27. assets/rmvpe/rmvpe.pt +3 -0
  28. assets/uvr5_weights/.gitignore +2 -0
  29. assets/weights/.gitignore +2 -0
  30. assets/weights/MJV2.pth +3 -0
  31. assets/weights/MJV2_e100_s100.pth +3 -0
  32. assets/weights/MJV2_e120_s120.pth +3 -0
  33. assets/weights/MJV2_e140_s140.pth +3 -0
  34. assets/weights/MJV2_e160_s160.pth +3 -0
  35. assets/weights/MJV2_e180_s180.pth +3 -0
  36. assets/weights/MJV2_e200_s200.pth +3 -0
  37. assets/weights/MJV2_e20_s20.pth +3 -0
  38. assets/weights/MJV2_e220_s220.pth +3 -0
  39. assets/weights/MJV2_e240_s240.pth +3 -0
  40. assets/weights/MJV2_e260_s260.pth +3 -0
  41. assets/weights/MJV2_e280_s280.pth +3 -0
  42. assets/weights/MJV2_e300_s300.pth +3 -0
  43. assets/weights/MJV2_e40_s40.pth +3 -0
  44. assets/weights/MJV2_e60_s60.pth +3 -0
  45. assets/weights/MJV2_e80_s80.pth +3 -0
  46. audios/somegirl.mp3 +0 -0
  47. audios/someguy.mp3 +0 -0
  48. audios/unachica.mp3 +0 -0
  49. audios/unchico.mp3 +0 -0
  50. configs/__pycache__/config.cpython-310.pyc +0 -0
.env ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ OPENBLAS_NUM_THREADS = 1
2
+ no_proxy = localhost, 127.0.0.1, ::1
3
+
4
+ # You can change the location of the model, etc. by changing here
5
+ weight_root = assets/weights
6
+ weight_uvr5_root = assets/uvr5_weights
7
+ index_root = logs
8
+ rmvpe_root = assets/rmvpe
.github/PULL_REQUEST_TEMPLATE.md ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pull request checklist
2
+
3
+ - [ ] The PR has a proper title. Use [Semantic Commit Messages](https://seesparkbox.com/foundry/semantic_commit_messages). (No more branch-name title please)
4
+ - [ ] Make sure you are requesting the right branch.
5
+ - [ ] Make sure this is ready to be merged into the relevant branch. Please don't create a PR and let it hang for a few days.
6
+ - [ ] Ensure all tests are passing.
7
+ - [ ] Ensure linting is passing.
8
+
9
+ # PR type
10
+
11
+ - Bug fix / new feature / chore
12
+
13
+ # Description
14
+
15
+ - Describe what this pull request is for.
16
+ - What will it affect.
17
+
18
+ # Screenshot
19
+
20
+ - Please include a screenshot if applicable
21
+
22
+ # Localhost url to test on
23
+
24
+ - Please include a url on localhost to test.
25
+
26
+ # Jira Link
27
+
28
+ - Please include a link to the ticket if applicable.
29
+
30
+ [Ticket]()
.github/workflows/docker.yml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build And Push Docker Image
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ # Sequence of patterns matched against refs/tags
7
+ tags:
8
+ - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ packages: write
15
+ contents: read
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Set time zone
19
+ uses: szenius/set-timezone@v1.0
20
+ with:
21
+ timezoneLinux: "Asia/Shanghai"
22
+ timezoneMacos: "Asia/Shanghai"
23
+ timezoneWindows: "China Standard Time"
24
+
25
+ # # 如果有 dockerhub 账户,可以在github的secrets中配置下面两个,然后取消下面注释的这几行,并在meta步骤的images增加一行 ${{ github.repository }}
26
+ # - name: Login to DockerHub
27
+ # uses: docker/login-action@v1
28
+ # with:
29
+ # username: ${{ secrets.DOCKERHUB_USERNAME }}
30
+ # password: ${{ secrets.DOCKERHUB_TOKEN }}
31
+
32
+ - name: Login to GHCR
33
+ uses: docker/login-action@v2
34
+ with:
35
+ registry: ghcr.io
36
+ username: ${{ github.repository_owner }}
37
+ password: ${{ secrets.GITHUB_TOKEN }}
38
+
39
+ - name: Extract metadata (tags, labels) for Docker
40
+ id: meta
41
+ uses: docker/metadata-action@v4
42
+ with:
43
+ images: |
44
+ ghcr.io/${{ github.repository }}
45
+ # generate Docker tags based on the following events/attributes
46
+ # nightly, master, pr-2, 1.2.3, 1.2, 1
47
+ tags: |
48
+ type=schedule,pattern=nightly
49
+ type=edge
50
+ type=ref,event=branch
51
+ type=ref,event=pr
52
+ type=semver,pattern={{version}}
53
+ type=semver,pattern={{major}}.{{minor}}
54
+ type=semver,pattern={{major}}
55
+
56
+ - name: Set up QEMU
57
+ uses: docker/setup-qemu-action@v2
58
+
59
+ - name: Set up Docker Buildx
60
+ uses: docker/setup-buildx-action@v2
61
+
62
+ - name: Build and push
63
+ id: docker_build
64
+ uses: docker/build-push-action@v4
65
+ with:
66
+ context: .
67
+ platforms: linux/amd64,linux/arm64
68
+ push: true
69
+ tags: ${{ steps.meta.outputs.tags }}
70
+ labels: ${{ steps.meta.outputs.labels }}
.github/workflows/genlocale.yml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: genlocale
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ jobs:
7
+ genlocale:
8
+ name: genlocale
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - name: Check out
12
+ uses: actions/checkout@master
13
+
14
+ - name: Run locale generation
15
+ run: |
16
+ python3 i18n/scan_i18n.py
17
+ cd i18n
18
+ python3 locale_diff.py
19
+
20
+ - name: Commit back
21
+ if: ${{ !github.head_ref }}
22
+ continue-on-error: true
23
+ run: |
24
+ git config --local user.name 'github-actions[bot]'
25
+ git config --local user.email 'github-actions[bot]@users.noreply.github.com'
26
+ git add --all
27
+ git commit -m "🎨 同步 locale"
28
+
29
+ - name: Create Pull Request
30
+ if: ${{ !github.head_ref }}
31
+ continue-on-error: true
32
+ uses: peter-evans/create-pull-request@v4
33
+
.github/workflows/pull_format.yml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: pull format
2
+
3
+ on: [pull_request]
4
+
5
+ permissions:
6
+ contents: write
7
+
8
+ jobs:
9
+ pull_format:
10
+ runs-on: ${{ matrix.os }}
11
+
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.10"]
15
+ os: [ubuntu-latest]
16
+ fail-fast: false
17
+
18
+ continue-on-error: true
19
+
20
+ steps:
21
+ - name: checkout
22
+ continue-on-error: true
23
+ uses: actions/checkout@v3
24
+ with:
25
+ ref: ${{ github.head_ref }}
26
+ fetch-depth: 0
27
+
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ uses: actions/setup-python@v4
30
+ with:
31
+ python-version: ${{ matrix.python-version }}
32
+
33
+ - name: Install Black
34
+ run: pip install "black[jupyter]"
35
+
36
+ - name: Run Black
37
+ # run: black $(git ls-files '*.py')
38
+ run: black .
.github/workflows/push_format.yml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: push format
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+ pull-requests: write
11
+
12
+ jobs:
13
+ push_format:
14
+ runs-on: ${{ matrix.os }}
15
+
16
+ strategy:
17
+ matrix:
18
+ python-version: ["3.10"]
19
+ os: [ubuntu-latest]
20
+ fail-fast: false
21
+
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ with:
25
+ ref: ${{github.ref_name}}
26
+
27
+ - name: Set up Python ${{ matrix.python-version }}
28
+ uses: actions/setup-python@v4
29
+ with:
30
+ python-version: ${{ matrix.python-version }}
31
+
32
+ - name: Install Black
33
+ run: pip install "black[jupyter]"
34
+
35
+ - name: Run Black
36
+ # run: black $(git ls-files '*.py')
37
+ run: black .
38
+
39
+ - name: Commit Back
40
+ continue-on-error: true
41
+ id: commitback
42
+ run: |
43
+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
44
+ git config --local user.name "github-actions[bot]"
45
+ git add --all
46
+ git commit -m "Format code"
47
+
48
+ - name: Create Pull Request
49
+ if: steps.commitback.outcome == 'success'
50
+ continue-on-error: true
51
+ uses: peter-evans/create-pull-request@v5
52
+ with:
53
+ delete-branch: true
54
+ body: Apply Code Formatter Change
55
+ title: Apply Code Formatter Change
56
+ commit-message: Automatic code format
.github/workflows/unitest.yml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: unitest
2
+ on: [ push, pull_request ]
3
+ jobs:
4
+ build:
5
+ runs-on: ${{ matrix.os }}
6
+ strategy:
7
+ matrix:
8
+ python-version: ["3.8", "3.9", "3.10"]
9
+ os: [ubuntu-latest]
10
+ fail-fast: false
11
+
12
+ steps:
13
+ - uses: actions/checkout@master
14
+ - name: Set up Python ${{ matrix.python-version }}
15
+ uses: actions/setup-python@v4
16
+ with:
17
+ python-version: ${{ matrix.python-version }}
18
+ - name: Install dependencies
19
+ run: |
20
+ sudo apt update
21
+ sudo apt -y install ffmpeg
22
+ sudo apt -y install -qq aria2
23
+ aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt -d ./ -o hubert_base.pt
24
+ python -m pip install --upgrade pip
25
+ python -m pip install --upgrade setuptools
26
+ python -m pip install --upgrade wheel
27
+ pip install torch torchvision torchaudio
28
+ pip install -r requirements.txt
29
+ - name: Test step 1 & 2
30
+ run: |
31
+ mkdir -p logs/mi-test
32
+ touch logs/mi-test/preprocess.log
33
+ python infer/modules/train/preprocess.py logs/mute/0_gt_wavs 48000 8 logs/mi-test True 3.7
34
+ touch logs/mi-test/extract_f0_feature.log
35
+ python infer/modules/train/extract/extract_f0_print.py logs/mi-test $(nproc) pm
36
+ python infer/modules/train/extract_feature_print.py cpu 1 0 0 logs/mi-test v1
.gitignore ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ __pycache__
3
+ /TEMP
4
+ *.pyd
5
+ .venv
6
+ /opt
7
+ tools/aria2c/
8
+ tools/flag.txt
9
+
10
+ # Imported from huggingface.co/lj1995/VoiceConversionWebUI
11
+ /pretrained
12
+ /pretrained_v2
13
+ /uvr5_weights
14
+ hubert_base.pt
15
+ rmvpe.onnx
16
+ rmvpe.pt
17
+
18
+ # Generated by RVC
19
+ /logs
20
+ /weights
21
+
22
+ # To set a Python version for the project
23
+ .tool-versions
Dockerfile ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1
2
+
3
+ FROM python:3.10-bullseye
4
+
5
+ EXPOSE 7865
6
+
7
+ WORKDIR /app
8
+
9
+ COPY . .
10
+
11
+ RUN apt update && apt install -y -qq ffmpeg aria2 && apt clean
12
+
13
+ RUN pip3 install --no-cache-dir -r requirements.txt
14
+
15
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/D40k.pth -d assets/pretrained_v2/ -o D40k.pth
16
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/G40k.pth -d assets/pretrained_v2/ -o G40k.pth
17
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0D40k.pth -d assets/pretrained_v2/ -o f0D40k.pth
18
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0G40k.pth -d assets/pretrained_v2/ -o f0G40k.pth
19
+
20
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP2-人声vocals+非人声instrumentals.pth -d assets/uvr5_weights/ -o HP2-人声vocals+非人声instrumentals.pth
21
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP5-主旋律人声vocals+其他instrumentals.pth -d assets/uvr5_weights/ -o HP5-主旋律人声vocals+其他instrumentals.pth
22
+
23
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt -d assets/hubert -o hubert_base.pt
24
+
25
+ RUN aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/rmvpe.pt -d assets/hubert -o rmvpe.pt
26
+
27
+ VOLUME [ "/app/weights", "/app/opt" ]
28
+
29
+ CMD ["python3", "infer-web.py"]
GUI.py ADDED
@@ -0,0 +1,1410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ import datetime, subprocess
3
+ from mega import Mega
4
+ now_dir = os.getcwd()
5
+ sys.path.append(now_dir)
6
+ import logging
7
+ import shutil
8
+ import threading
9
+ import traceback
10
+ import warnings
11
+ from random import shuffle
12
+ from subprocess import Popen
13
+ from time import sleep
14
+ import json
15
+ import pathlib
16
+
17
+ import fairseq
18
+ import faiss
19
+ import gradio as gr
20
+ import numpy as np
21
+ import torch
22
+ from dotenv import load_dotenv
23
+ from sklearn.cluster import MiniBatchKMeans
24
+
25
+ from configs.config import Config
26
+ from i18n.i18n import I18nAuto
27
+ from infer.lib.train.process_ckpt import (
28
+ change_info,
29
+ extract_small_model,
30
+ merge,
31
+ show_info,
32
+ )
33
+ from infer.modules.uvr5.modules import uvr
34
+ from infer.modules.vc.modules import VC
35
+ logging.getLogger("numba").setLevel(logging.WARNING)
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+ tmp = os.path.join(now_dir, "TEMP")
40
+ shutil.rmtree(tmp, ignore_errors=True)
41
+ shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
42
+ shutil.rmtree("%s/runtime/Lib/site-packages/uvr5_pack" % (now_dir), ignore_errors=True)
43
+ os.makedirs(tmp, exist_ok=True)
44
+ os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
45
+ os.makedirs(os.path.join(now_dir, "assets/weights"), exist_ok=True)
46
+ os.environ["TEMP"] = tmp
47
+ warnings.filterwarnings("ignore")
48
+ torch.manual_seed(114514)
49
+
50
+
51
+ load_dotenv()
52
+ config = Config()
53
+ vc = VC(config)
54
+
55
+ if config.dml == True:
56
+
57
+ def forward_dml(ctx, x, scale):
58
+ ctx.scale = scale
59
+ res = x.clone().detach()
60
+ return res
61
+
62
+ fairseq.modules.grad_multiply.GradMultiply.forward = forward_dml
63
+ i18n = I18nAuto()
64
+ logger.info(i18n)
65
+ # 判断是否有能用来训练和加速推理的N卡
66
+ ngpu = torch.cuda.device_count()
67
+ gpu_infos = []
68
+ mem = []
69
+ if_gpu_ok = False
70
+
71
+ if torch.cuda.is_available() or ngpu != 0:
72
+ for i in range(ngpu):
73
+ gpu_name = torch.cuda.get_device_name(i)
74
+ if any(
75
+ value in gpu_name.upper()
76
+ for value in [
77
+ "10",
78
+ "16",
79
+ "20",
80
+ "30",
81
+ "40",
82
+ "A2",
83
+ "A3",
84
+ "A4",
85
+ "P4",
86
+ "A50",
87
+ "500",
88
+ "A60",
89
+ "70",
90
+ "80",
91
+ "90",
92
+ "M4",
93
+ "T4",
94
+ "TITAN",
95
+ ]
96
+ ):
97
+ # A10#A100#V100#A40#P40#M40#K80#A4500
98
+ if_gpu_ok = True # 至少有一张能用的N卡
99
+ gpu_infos.append("%s\t%s" % (i, gpu_name))
100
+ mem.append(
101
+ int(
102
+ torch.cuda.get_device_properties(i).total_memory
103
+ / 1024
104
+ / 1024
105
+ / 1024
106
+ + 0.4
107
+ )
108
+ )
109
+ if if_gpu_ok and len(gpu_infos) > 0:
110
+ gpu_info = "\n".join(gpu_infos)
111
+ default_batch_size = min(mem) // 2
112
+ else:
113
+ gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
114
+ default_batch_size = 1
115
+ gpus = "-".join([i[0] for i in gpu_infos])
116
+
117
+
118
+ class ToolButton(gr.Button, gr.components.FormComponent):
119
+ """Small button with single emoji as text, fits inside gradio forms"""
120
+
121
+ def __init__(self, **kwargs):
122
+ super().__init__(variant="tool", **kwargs)
123
+
124
+ def get_block_name(self):
125
+ return "button"
126
+
127
+
128
+ weight_root = os.getenv("weight_root")
129
+ weight_uvr5_root = os.getenv("weight_uvr5_root")
130
+ index_root = os.getenv("index_root")
131
+
132
+ names = []
133
+ for name in os.listdir(weight_root):
134
+ if name.endswith(".pth"):
135
+ names.append(name)
136
+ index_paths = []
137
+ for root, dirs, files in os.walk(index_root, topdown=False):
138
+ for name in files:
139
+ if name.endswith(".index") and "trained" not in name:
140
+ index_paths.append("%s/%s" % (root, name))
141
+ uvr5_names = []
142
+ for name in os.listdir(weight_uvr5_root):
143
+ if name.endswith(".pth") or "onnx" in name:
144
+ uvr5_names.append(name.replace(".pth", ""))
145
+
146
+
147
+ def change_choices():
148
+ names = []
149
+ for name in os.listdir(weight_root):
150
+ if name.endswith(".pth"):
151
+ names.append(name)
152
+ index_paths = []
153
+ for root, dirs, files in os.walk(index_root, topdown=False):
154
+ for name in files:
155
+ if name.endswith(".index") and "trained" not in name:
156
+ index_paths.append("%s/%s" % (root, name))
157
+ audio_files=[]
158
+ for filename in os.listdir("./audios"):
159
+ if filename.endswith(('.wav','.mp3','.ogg')):
160
+ audio_files.append('./audios/'+filename)
161
+ return {"choices": sorted(names), "__type__": "update"}, {
162
+ "choices": sorted(index_paths),
163
+ "__type__": "update",
164
+ }, {"choices": sorted(audio_files), "__type__": "update"}
165
+
166
+ def clean():
167
+ return {"value": "", "__type__": "update"}
168
+
169
+
170
+ def export_onnx():
171
+ from infer.modules.onnx.export import export_onnx as eo
172
+
173
+ eo()
174
+
175
+
176
+ sr_dict = {
177
+ "32k": 32000,
178
+ "40k": 40000,
179
+ "48k": 48000,
180
+ }
181
+
182
+
183
+ def if_done(done, p):
184
+ while 1:
185
+ if p.poll() is None:
186
+ sleep(0.5)
187
+ else:
188
+ break
189
+ done[0] = True
190
+
191
+
192
+ def if_done_multi(done, ps):
193
+ while 1:
194
+ # poll==None代表进程未结束
195
+ # 只要有一个进程未结束都不停
196
+ flag = 1
197
+ for p in ps:
198
+ if p.poll() is None:
199
+ flag = 0
200
+ sleep(0.5)
201
+ break
202
+ if flag == 1:
203
+ break
204
+ done[0] = True
205
+
206
+
207
+ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
208
+ sr = sr_dict[sr]
209
+ os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
210
+ f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
211
+ f.close()
212
+ per = 3.0 if config.is_half else 3.7
213
+ cmd = '"%s" infer/modules/train/preprocess.py "%s" %s %s "%s/logs/%s" %s %.1f' % (
214
+ config.python_cmd,
215
+ trainset_dir,
216
+ sr,
217
+ n_p,
218
+ now_dir,
219
+ exp_dir,
220
+ config.noparallel,
221
+ per,
222
+ )
223
+ logger.info(cmd)
224
+ p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
225
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
226
+ done = [False]
227
+ threading.Thread(
228
+ target=if_done,
229
+ args=(
230
+ done,
231
+ p,
232
+ ),
233
+ ).start()
234
+ while 1:
235
+ with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
236
+ yield (f.read())
237
+ sleep(1)
238
+ if done[0]:
239
+ break
240
+ with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
241
+ log = f.read()
242
+ logger.info(log)
243
+ yield log
244
+
245
+
246
+ # but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
247
+ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvpe):
248
+ gpus = gpus.split("-")
249
+ os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
250
+ f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
251
+ f.close()
252
+ if if_f0:
253
+ if f0method != "rmvpe_gpu":
254
+ cmd = (
255
+ '"%s" infer/modules/train/extract/extract_f0_print.py "%s/logs/%s" %s %s'
256
+ % (
257
+ config.python_cmd,
258
+ now_dir,
259
+ exp_dir,
260
+ n_p,
261
+ f0method,
262
+ )
263
+ )
264
+ logger.info(cmd)
265
+ p = Popen(
266
+ cmd, shell=True, cwd=now_dir
267
+ ) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
268
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
269
+ done = [False]
270
+ threading.Thread(
271
+ target=if_done,
272
+ args=(
273
+ done,
274
+ p,
275
+ ),
276
+ ).start()
277
+ else:
278
+ if gpus_rmvpe != "-":
279
+ gpus_rmvpe = gpus_rmvpe.split("-")
280
+ leng = len(gpus_rmvpe)
281
+ ps = []
282
+ for idx, n_g in enumerate(gpus_rmvpe):
283
+ cmd = (
284
+ '"%s" infer/modules/train/extract/extract_f0_rmvpe.py %s %s %s "%s/logs/%s" %s '
285
+ % (
286
+ config.python_cmd,
287
+ leng,
288
+ idx,
289
+ n_g,
290
+ now_dir,
291
+ exp_dir,
292
+ config.is_half,
293
+ )
294
+ )
295
+ logger.info(cmd)
296
+ p = Popen(
297
+ cmd, shell=True, cwd=now_dir
298
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
299
+ ps.append(p)
300
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
301
+ done = [False]
302
+ threading.Thread(
303
+ target=if_done_multi, #
304
+ args=(
305
+ done,
306
+ ps,
307
+ ),
308
+ ).start()
309
+ else:
310
+ cmd = (
311
+ config.python_cmd
312
+ + ' infer/modules/train/extract/extract_f0_rmvpe_dml.py "%s/logs/%s" '
313
+ % (
314
+ now_dir,
315
+ exp_dir,
316
+ )
317
+ )
318
+ logger.info(cmd)
319
+ p = Popen(
320
+ cmd, shell=True, cwd=now_dir
321
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
322
+ p.wait()
323
+ done = [True]
324
+ while 1:
325
+ with open(
326
+ "%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
327
+ ) as f:
328
+ yield (f.read())
329
+ sleep(1)
330
+ if done[0]:
331
+ break
332
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
333
+ log = f.read()
334
+ logger.info(log)
335
+ yield log
336
+ ####对不同part分别开多进程
337
+ """
338
+ n_part=int(sys.argv[1])
339
+ i_part=int(sys.argv[2])
340
+ i_gpu=sys.argv[3]
341
+ exp_dir=sys.argv[4]
342
+ os.environ["CUDA_VISIBLE_DEVICES"]=str(i_gpu)
343
+ """
344
+ leng = len(gpus)
345
+ ps = []
346
+ for idx, n_g in enumerate(gpus):
347
+ cmd = (
348
+ '"%s" infer/modules/train/extract_feature_print.py %s %s %s %s "%s/logs/%s" %s'
349
+ % (
350
+ config.python_cmd,
351
+ config.device,
352
+ leng,
353
+ idx,
354
+ n_g,
355
+ now_dir,
356
+ exp_dir,
357
+ version19,
358
+ )
359
+ )
360
+ logger.info(cmd)
361
+ p = Popen(
362
+ cmd, shell=True, cwd=now_dir
363
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
364
+ ps.append(p)
365
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
366
+ done = [False]
367
+ threading.Thread(
368
+ target=if_done_multi,
369
+ args=(
370
+ done,
371
+ ps,
372
+ ),
373
+ ).start()
374
+ while 1:
375
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
376
+ yield (f.read())
377
+ sleep(1)
378
+ if done[0]:
379
+ break
380
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
381
+ log = f.read()
382
+ logger.info(log)
383
+ yield log
384
+
385
+
386
+ def get_pretrained_models(path_str, f0_str, sr2):
387
+ if_pretrained_generator_exist = os.access(
388
+ "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK
389
+ )
390
+ if_pretrained_discriminator_exist = os.access(
391
+ "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), os.F_OK
392
+ )
393
+ if not if_pretrained_generator_exist:
394
+ logger.warn(
395
+ "assets/pretrained%s/%sG%s.pth not exist, will not use pretrained model",
396
+ path_str,
397
+ f0_str,
398
+ sr2,
399
+ )
400
+ if not if_pretrained_discriminator_exist:
401
+ logger.warn(
402
+ "assets/pretrained%s/%sD%s.pth not exist, will not use pretrained model",
403
+ path_str,
404
+ f0_str,
405
+ sr2,
406
+ )
407
+ return (
408
+ "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2)
409
+ if if_pretrained_generator_exist
410
+ else "",
411
+ "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
412
+ if if_pretrained_discriminator_exist
413
+ else "",
414
+ )
415
+
416
+
417
+ def change_sr2(sr2, if_f0_3, version19):
418
+ path_str = "" if version19 == "v1" else "_v2"
419
+ f0_str = "f0" if if_f0_3 else ""
420
+ return get_pretrained_models(path_str, f0_str, sr2)
421
+
422
+
423
+ def change_version19(sr2, if_f0_3, version19):
424
+ path_str = "" if version19 == "v1" else "_v2"
425
+ if sr2 == "32k" and version19 == "v1":
426
+ sr2 = "40k"
427
+ to_return_sr2 = (
428
+ {"choices": ["40k", "48k"], "__type__": "update", "value": sr2}
429
+ if version19 == "v1"
430
+ else {"choices": ["40k", "48k", "32k"], "__type__": "update", "value": sr2}
431
+ )
432
+ f0_str = "f0" if if_f0_3 else ""
433
+ return (
434
+ *get_pretrained_models(path_str, f0_str, sr2),
435
+ to_return_sr2,
436
+ )
437
+
438
+
439
+ def change_f0(if_f0_3, sr2, version19): # f0method8,pretrained_G14,pretrained_D15
440
+ path_str = "" if version19 == "v1" else "_v2"
441
+ return (
442
+ {"visible": if_f0_3, "__type__": "update"},
443
+ *get_pretrained_models(path_str, "f0", sr2),
444
+ )
445
+
446
+
447
+ # but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
448
+ def click_train(
449
+ exp_dir1,
450
+ sr2,
451
+ if_f0_3,
452
+ spk_id5,
453
+ save_epoch10,
454
+ total_epoch11,
455
+ batch_size12,
456
+ if_save_latest13,
457
+ pretrained_G14,
458
+ pretrained_D15,
459
+ gpus16,
460
+ if_cache_gpu17,
461
+ if_save_every_weights18,
462
+ version19,
463
+ ):
464
+ # 生成filelist
465
+ exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
466
+ os.makedirs(exp_dir, exist_ok=True)
467
+ gt_wavs_dir = "%s/0_gt_wavs" % (exp_dir)
468
+ feature_dir = (
469
+ "%s/3_feature256" % (exp_dir)
470
+ if version19 == "v1"
471
+ else "%s/3_feature768" % (exp_dir)
472
+ )
473
+ if if_f0_3:
474
+ f0_dir = "%s/2a_f0" % (exp_dir)
475
+ f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
476
+ names = (
477
+ set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
478
+ & set([name.split(".")[0] for name in os.listdir(feature_dir)])
479
+ & set([name.split(".")[0] for name in os.listdir(f0_dir)])
480
+ & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
481
+ )
482
+ else:
483
+ names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
484
+ [name.split(".")[0] for name in os.listdir(feature_dir)]
485
+ )
486
+ opt = []
487
+ for name in names:
488
+ if if_f0_3:
489
+ opt.append(
490
+ "%s/%s.wav|%s/%s.npy|%s/%s.wav.npy|%s/%s.wav.npy|%s"
491
+ % (
492
+ gt_wavs_dir.replace("\\", "\\\\"),
493
+ name,
494
+ feature_dir.replace("\\", "\\\\"),
495
+ name,
496
+ f0_dir.replace("\\", "\\\\"),
497
+ name,
498
+ f0nsf_dir.replace("\\", "\\\\"),
499
+ name,
500
+ spk_id5,
501
+ )
502
+ )
503
+ else:
504
+ opt.append(
505
+ "%s/%s.wav|%s/%s.npy|%s"
506
+ % (
507
+ gt_wavs_dir.replace("\\", "\\\\"),
508
+ name,
509
+ feature_dir.replace("\\", "\\\\"),
510
+ name,
511
+ spk_id5,
512
+ )
513
+ )
514
+ fea_dim = 256 if version19 == "v1" else 768
515
+ if if_f0_3:
516
+ for _ in range(2):
517
+ opt.append(
518
+ "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s/logs/mute/2a_f0/mute.wav.npy|%s/logs/mute/2b-f0nsf/mute.wav.npy|%s"
519
+ % (now_dir, sr2, now_dir, fea_dim, now_dir, now_dir, spk_id5)
520
+ )
521
+ else:
522
+ for _ in range(2):
523
+ opt.append(
524
+ "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s"
525
+ % (now_dir, sr2, now_dir, fea_dim, spk_id5)
526
+ )
527
+ shuffle(opt)
528
+ with open("%s/filelist.txt" % exp_dir, "w") as f:
529
+ f.write("\n".join(opt))
530
+ logger.debug("Write filelist done")
531
+ # 生成config#无需生成config
532
+ # cmd = python_cmd + " train_nsf_sim_cache_sid_load_pretrain.py -e mi-test -sr 40k -f0 1 -bs 4 -g 0 -te 10 -se 5 -pg pretrained/f0G40k.pth -pd pretrained/f0D40k.pth -l 1 -c 0"
533
+ logger.info("Use gpus: %s", str(gpus16))
534
+ if pretrained_G14 == "":
535
+ logger.info("No pretrained Generator")
536
+ if pretrained_D15 == "":
537
+ logger.info("No pretrained Discriminator")
538
+ if version19 == "v1" or sr2 == "40k":
539
+ config_path = "v1/%s.json" % sr2
540
+ else:
541
+ config_path = "v2/%s.json" % sr2
542
+ config_save_path = os.path.join(exp_dir, "config.json")
543
+ if not pathlib.Path(config_save_path).exists():
544
+ with open(config_save_path, "w", encoding="utf-8") as f:
545
+ json.dump(
546
+ config.json_config[config_path],
547
+ f,
548
+ ensure_ascii=False,
549
+ indent=4,
550
+ sort_keys=True,
551
+ )
552
+ f.write("\n")
553
+ if gpus16:
554
+ cmd = (
555
+ '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
556
+ % (
557
+ config.python_cmd,
558
+ exp_dir1,
559
+ sr2,
560
+ 1 if if_f0_3 else 0,
561
+ batch_size12,
562
+ gpus16,
563
+ total_epoch11,
564
+ save_epoch10,
565
+ "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
566
+ "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
567
+ 1 if if_save_latest13 == i18n("是") else 0,
568
+ 1 if if_cache_gpu17 == i18n("是") else 0,
569
+ 1 if if_save_every_weights18 == i18n("是") else 0,
570
+ version19,
571
+ )
572
+ )
573
+ else:
574
+ cmd = (
575
+ '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
576
+ % (
577
+ config.python_cmd,
578
+ exp_dir1,
579
+ sr2,
580
+ 1 if if_f0_3 else 0,
581
+ batch_size12,
582
+ total_epoch11,
583
+ save_epoch10,
584
+ "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
585
+ "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
586
+ 1 if if_save_latest13 == i18n("是") else 0,
587
+ 1 if if_cache_gpu17 == i18n("是") else 0,
588
+ 1 if if_save_every_weights18 == i18n("是") else 0,
589
+ version19,
590
+ )
591
+ )
592
+ logger.info(cmd)
593
+ p = Popen(cmd, shell=True, cwd=now_dir)
594
+ p.wait()
595
+ return "训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"
596
+
597
+
598
+ # but4.click(train_index, [exp_dir1], info3)
599
+ def train_index(exp_dir1, version19):
600
+ # exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
601
+ exp_dir = "logs/%s" % (exp_dir1)
602
+ os.makedirs(exp_dir, exist_ok=True)
603
+ feature_dir = (
604
+ "%s/3_feature256" % (exp_dir)
605
+ if version19 == "v1"
606
+ else "%s/3_feature768" % (exp_dir)
607
+ )
608
+ if not os.path.exists(feature_dir):
609
+ return "请先进行特征提取!"
610
+ listdir_res = list(os.listdir(feature_dir))
611
+ if len(listdir_res) == 0:
612
+ return "请先进行特征提取!"
613
+ infos = []
614
+ npys = []
615
+ for name in sorted(listdir_res):
616
+ phone = np.load("%s/%s" % (feature_dir, name))
617
+ npys.append(phone)
618
+ big_npy = np.concatenate(npys, 0)
619
+ big_npy_idx = np.arange(big_npy.shape[0])
620
+ np.random.shuffle(big_npy_idx)
621
+ big_npy = big_npy[big_npy_idx]
622
+ if big_npy.shape[0] > 2e5:
623
+ infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
624
+ yield "\n".join(infos)
625
+ try:
626
+ big_npy = (
627
+ MiniBatchKMeans(
628
+ n_clusters=10000,
629
+ verbose=True,
630
+ batch_size=256 * config.n_cpu,
631
+ compute_labels=False,
632
+ init="random",
633
+ )
634
+ .fit(big_npy)
635
+ .cluster_centers_
636
+ )
637
+ except:
638
+ info = traceback.format_exc()
639
+ logger.info(info)
640
+ infos.append(info)
641
+ yield "\n".join(infos)
642
+
643
+ np.save("%s/total_fea.npy" % exp_dir, big_npy)
644
+ n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
645
+ infos.append("%s,%s" % (big_npy.shape, n_ivf))
646
+ yield "\n".join(infos)
647
+ index = faiss.index_factory(256 if version19 == "v1" else 768, "IVF%s,Flat" % n_ivf)
648
+ # index = faiss.index_factory(256if version19=="v1"else 768, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
649
+ infos.append("training")
650
+ yield "\n".join(infos)
651
+ index_ivf = faiss.extract_index_ivf(index) #
652
+ index_ivf.nprobe = 1
653
+ index.train(big_npy)
654
+ faiss.write_index(
655
+ index,
656
+ "%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
657
+ % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
658
+ )
659
+
660
+ infos.append("adding")
661
+ yield "\n".join(infos)
662
+ batch_size_add = 8192
663
+ for i in range(0, big_npy.shape[0], batch_size_add):
664
+ index.add(big_npy[i : i + batch_size_add])
665
+ faiss.write_index(
666
+ index,
667
+ "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
668
+ % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
669
+ )
670
+ infos.append(
671
+ "成功构建索引,added_IVF%s_Flat_nprobe_%s_%s_%s.index"
672
+ % (n_ivf, index_ivf.nprobe, exp_dir1, version19)
673
+ )
674
+ # faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan_%s.index'%(exp_dir,n_ivf,version19))
675
+ # infos.append("成功构建索引,added_IVF%s_Flat_FastScan_%s.index"%(n_ivf,version19))
676
+ yield "\n".join(infos)
677
+
678
+
679
+ # but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
680
+ def train1key(
681
+ exp_dir1,
682
+ sr2,
683
+ if_f0_3,
684
+ trainset_dir4,
685
+ spk_id5,
686
+ np7,
687
+ f0method8,
688
+ save_epoch10,
689
+ total_epoch11,
690
+ batch_size12,
691
+ if_save_latest13,
692
+ pretrained_G14,
693
+ pretrained_D15,
694
+ gpus16,
695
+ if_cache_gpu17,
696
+ if_save_every_weights18,
697
+ version19,
698
+ gpus_rmvpe,
699
+ ):
700
+ infos = []
701
+
702
+ def get_info_str(strr):
703
+ infos.append(strr)
704
+ return "\n".join(infos)
705
+
706
+ ####### step1:处理数据
707
+ yield get_info_str(i18n("step1:正在处理数据"))
708
+ [get_info_str(_) for _ in preprocess_dataset(trainset_dir4, exp_dir1, sr2, np7)]
709
+
710
+ ####### step2a:提取音高
711
+ yield get_info_str(i18n("step2:正在提取音高&正在提取特征"))
712
+ [
713
+ get_info_str(_)
714
+ for _ in extract_f0_feature(
715
+ gpus16, np7, f0method8, if_f0_3, exp_dir1, version19, gpus_rmvpe
716
+ )
717
+ ]
718
+
719
+ ####### step3a:训练模型
720
+ yield get_info_str(i18n("step3a:正在训练模型"))
721
+ click_train(
722
+ exp_dir1,
723
+ sr2,
724
+ if_f0_3,
725
+ spk_id5,
726
+ save_epoch10,
727
+ total_epoch11,
728
+ batch_size12,
729
+ if_save_latest13,
730
+ pretrained_G14,
731
+ pretrained_D15,
732
+ gpus16,
733
+ if_cache_gpu17,
734
+ if_save_every_weights18,
735
+ version19,
736
+ )
737
+ yield get_info_str(i18n("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"))
738
+
739
+ ####### step3b:训练索引
740
+ [get_info_str(_) for _ in train_index(exp_dir1, version19)]
741
+ yield get_info_str(i18n("全流程结束!"))
742
+
743
+
744
+ # ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
745
+ def change_info_(ckpt_path):
746
+ if not os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log")):
747
+ return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
748
+ try:
749
+ with open(
750
+ ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
751
+ ) as f:
752
+ info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
753
+ sr, f0 = info["sample_rate"], info["if_f0"]
754
+ version = "v2" if ("version" in info and info["version"] == "v2") else "v1"
755
+ return sr, str(f0), version
756
+ except:
757
+ traceback.print_exc()
758
+ return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
759
+
760
+
761
+ F0GPUVisible = config.dml == False
762
+
763
+
764
+ def change_f0_method(f0method8):
765
+ if f0method8 == "rmvpe_gpu":
766
+ visible = F0GPUVisible
767
+ else:
768
+ visible = False
769
+ return {"visible": visible, "__type__": "update"}
770
+
771
+ def find_model():
772
+ if len(names) > 0:
773
+ vc.get_vc(sorted(names)[0],None,None)
774
+ return sorted(names)[0]
775
+ else:
776
+ try:
777
+ gr.Info("Do not forget to choose a model.")
778
+ except:
779
+ pass
780
+ return ''
781
+
782
+ def find_audios(index=False):
783
+ audio_files=[]
784
+ if not os.path.exists('./audios'): os.mkdir("./audios")
785
+ for filename in os.listdir("./audios"):
786
+ if filename.endswith(('.wav','.mp3','.ogg')):
787
+ audio_files.append("./audios/"+filename)
788
+ if index:
789
+ if len(audio_files) > 0: return sorted(audio_files)[0]
790
+ else: return ""
791
+ elif len(audio_files) > 0: return sorted(audio_files)
792
+ else: return []
793
+
794
+ def get_index():
795
+ if find_model() != '':
796
+ chosen_model=sorted(names)[0].split(".")[0]
797
+ logs_path="./logs/"+chosen_model
798
+ if os.path.exists(logs_path):
799
+ for file in os.listdir(logs_path):
800
+ if file.endswith(".index"):
801
+ return os.path.join(logs_path, file)
802
+ return ''
803
+ else:
804
+ return ''
805
+
806
+ def get_indexes():
807
+ indexes_list=[]
808
+ for dirpath, dirnames, filenames in os.walk("./logs/"):
809
+ for filename in filenames:
810
+ if filename.endswith(".index"):
811
+ indexes_list.append(os.path.join(dirpath,filename))
812
+ if len(indexes_list) > 0:
813
+ return indexes_list
814
+ else:
815
+ return ''
816
+
817
+ def save_wav(file):
818
+ try:
819
+ file_path=file.name
820
+ shutil.move(file_path,'./audios')
821
+ return './audios/'+os.path.basename(file_path)
822
+ except AttributeError:
823
+ try:
824
+ new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+'.wav'
825
+ new_path='./audios/'+new_name
826
+ shutil.move(file,new_path)
827
+ return new_path
828
+ except TypeError:
829
+ return None
830
+
831
+ def download_from_url(url, model):
832
+ if url == '':
833
+ return "URL cannot be left empty."
834
+ if model =='':
835
+ return "You need to name your model. For example: My-Model"
836
+ url = url.strip()
837
+ zip_dirs = ["zips", "unzips"]
838
+ for directory in zip_dirs:
839
+ if os.path.exists(directory):
840
+ shutil.rmtree(directory)
841
+ os.makedirs("zips", exist_ok=True)
842
+ os.makedirs("unzips", exist_ok=True)
843
+ zipfile = model + '.zip'
844
+ zipfile_path = './zips/' + zipfile
845
+ try:
846
+ if "drive.google.com" in url:
847
+ subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
848
+ elif "mega.nz" in url:
849
+ m = Mega()
850
+ m.download_url(url, './zips')
851
+ else:
852
+ subprocess.run(["wget", url, "-O", zipfile_path])
853
+ for filename in os.listdir("./zips"):
854
+ if filename.endswith(".zip"):
855
+ zipfile_path = os.path.join("./zips/",filename)
856
+ shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
857
+ else:
858
+ return "No zipfile found."
859
+ for root, dirs, files in os.walk('./unzips'):
860
+ for file in files:
861
+ file_path = os.path.join(root, file)
862
+ if file.endswith(".index"):
863
+ os.mkdir(f'./logs/{model}')
864
+ shutil.copy2(file_path,f'./logs/{model}')
865
+ elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
866
+ shutil.copy(file_path,f'./assets/weights/{model}.pth')
867
+ shutil.rmtree("zips")
868
+ shutil.rmtree("unzips")
869
+ return "Success."
870
+ except:
871
+ return "There's been an error."
872
+
873
+ def upload_to_dataset(files, dir):
874
+ if dir == '':
875
+ dir = './dataset/'+datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
876
+ if not os.path.exists(dir):
877
+ os.makedirs(dir)
878
+ for file in files:
879
+ path=file.name
880
+ shutil.copy2(path,dir)
881
+ try:
882
+ gr.Info(i18n("处理数据"))
883
+ except:
884
+ pass
885
+ return i18n("处理数据"), {"value":dir,"__type__":"update"}
886
+
887
+ with gr.Blocks(title="EasyGUI v2.9",theme=gr.themes.Base()) as app:
888
+ gr.HTML("<h1> EasyGUI v2.9 </h1>")
889
+ with gr.Tabs():
890
+ with gr.TabItem(i18n("模型推理")):
891
+ with gr.Row():
892
+ sid0 = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names), value=find_model())
893
+ refresh_button = gr.Button(i18n("刷新音色列表和索引路径"), variant="primary")
894
+ #clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
895
+ spk_item = gr.Slider(
896
+ minimum=0,
897
+ maximum=2333,
898
+ step=1,
899
+ label=i18n("请选择说话人id"),
900
+ value=0,
901
+ visible=False,
902
+ interactive=True,
903
+ )
904
+ #clean_button.click(
905
+ # fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean"
906
+ #)
907
+ vc_transform0 = gr.Number(
908
+ label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
909
+ )
910
+ but0 = gr.Button(i18n("转换"), variant="primary")
911
+ with gr.Row():
912
+ with gr.Column():
913
+ with gr.Row():
914
+ dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
915
+ with gr.Row():
916
+ record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
917
+ with gr.Row():
918
+ input_audio0 = gr.Dropdown(
919
+ label=i18n("输入待处理音频文件路径(默认是正确格式示例)"),
920
+ value=find_audios(True),
921
+ choices=find_audios()
922
+ )
923
+ record_button.change(fn=save_wav, inputs=[record_button], outputs=[input_audio0])
924
+ dropbox.upload(fn=save_wav, inputs=[dropbox], outputs=[input_audio0])
925
+ with gr.Column():
926
+ with gr.Accordion(label=i18n("自动检测index路径,下拉式选择(dropdown)"), open=False):
927
+ file_index2 = gr.Dropdown(
928
+ label=i18n("自动检测index路径,下拉式选择(dropdown)"),
929
+ choices=get_indexes(),
930
+ interactive=True,
931
+ value=get_index()
932
+ )
933
+ index_rate1 = gr.Slider(
934
+ minimum=0,
935
+ maximum=1,
936
+ label=i18n("检索特征占比"),
937
+ value=0.66,
938
+ interactive=True,
939
+ )
940
+ vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
941
+ with gr.Accordion(label=i18n("常规设置"), open=False):
942
+ f0method0 = gr.Radio(
943
+ label=i18n(
944
+ "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
945
+ ),
946
+ choices=["pm", "harvest", "crepe", "rmvpe"]
947
+ if config.dml == False
948
+ else ["pm", "harvest", "rmvpe"],
949
+ value="rmvpe",
950
+ interactive=True,
951
+ )
952
+ filter_radius0 = gr.Slider(
953
+ minimum=0,
954
+ maximum=7,
955
+ label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
956
+ value=3,
957
+ step=1,
958
+ interactive=True,
959
+ )
960
+ resample_sr0 = gr.Slider(
961
+ minimum=0,
962
+ maximum=48000,
963
+ label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
964
+ value=0,
965
+ step=1,
966
+ interactive=True,
967
+ )
968
+ rms_mix_rate0 = gr.Slider(
969
+ minimum=0,
970
+ maximum=1,
971
+ label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
972
+ value=0.21,
973
+ interactive=True,
974
+ )
975
+ protect0 = gr.Slider(
976
+ minimum=0,
977
+ maximum=0.5,
978
+ label=i18n(
979
+ "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
980
+ ),
981
+ value=0.33,
982
+ step=0.01,
983
+ interactive=True,
984
+ )
985
+ file_index1 = gr.Textbox(
986
+ label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
987
+ value="",
988
+ interactive=True,
989
+ visible=False
990
+ )
991
+ refresh_button.click(
992
+ fn=change_choices,
993
+ inputs=[],
994
+ outputs=[sid0, file_index2, input_audio0],
995
+ api_name="infer_refresh",
996
+ )
997
+ # file_big_npy1 = gr.Textbox(
998
+ # label=i18n("特征文件路径"),
999
+ # value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1000
+ # interactive=True,
1001
+ # )
1002
+ with gr.Row():
1003
+ f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
1004
+ with gr.Row():
1005
+ vc_output1 = gr.Textbox(label=i18n("输出信息"))
1006
+ but0.click(
1007
+ vc.vc_single,
1008
+ [
1009
+ spk_item,
1010
+ input_audio0,
1011
+ vc_transform0,
1012
+ f0_file,
1013
+ f0method0,
1014
+ file_index1,
1015
+ file_index2,
1016
+ # file_big_npy1,
1017
+ index_rate1,
1018
+ filter_radius0,
1019
+ resample_sr0,
1020
+ rms_mix_rate0,
1021
+ protect0,
1022
+ ],
1023
+ [vc_output1, vc_output2],
1024
+ api_name="infer_convert",
1025
+ )
1026
+ with gr.Row():
1027
+ with gr.Accordion(open=False, label=i18n("批量转换, 输入待转换音频文件夹, 或上传多个音频文件, 在指定文件夹(默认opt)下输出转换的音频. ")):
1028
+ with gr.Column():
1029
+ vc_transform1 = gr.Number(
1030
+ label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
1031
+ )
1032
+ opt_input = gr.Textbox(label=i18n("指定输出文件夹"), value="opt")
1033
+ f0method1 = gr.Radio(
1034
+ label=i18n(
1035
+ "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
1036
+ ),
1037
+ choices=["pm", "harvest", "crepe", "rmvpe"]
1038
+ if config.dml == False
1039
+ else ["pm", "harvest", "rmvpe"],
1040
+ value="pm",
1041
+ interactive=True,
1042
+ )
1043
+ filter_radius1 = gr.Slider(
1044
+ minimum=0,
1045
+ maximum=7,
1046
+ label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
1047
+ value=3,
1048
+ step=1,
1049
+ interactive=True,
1050
+ )
1051
+ with gr.Column():
1052
+ file_index3 = gr.Textbox(
1053
+ label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
1054
+ value="",
1055
+ interactive=True,
1056
+ visible=False
1057
+ )
1058
+ file_index4 = gr.Dropdown(
1059
+ label=i18n("自动检测index路径,下拉式选择(dropdown)"),
1060
+ choices=sorted(index_paths),
1061
+ interactive=True,
1062
+ )
1063
+ refresh_button.click(
1064
+ fn=lambda: change_choices()[1],
1065
+ inputs=[],
1066
+ outputs=file_index4,
1067
+ api_name="infer_refresh_batch",
1068
+ )
1069
+ # file_big_npy2 = gr.Textbox(
1070
+ # label=i18n("特征文件路径"),
1071
+ # value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1072
+ # interactive=True,
1073
+ # )
1074
+ index_rate2 = gr.Slider(
1075
+ minimum=0,
1076
+ maximum=1,
1077
+ label=i18n("检索特征占比"),
1078
+ value=1,
1079
+ interactive=True,
1080
+ )
1081
+ with gr.Column():
1082
+ resample_sr1 = gr.Slider(
1083
+ minimum=0,
1084
+ maximum=48000,
1085
+ label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
1086
+ value=0,
1087
+ step=1,
1088
+ interactive=True,
1089
+ )
1090
+ rms_mix_rate1 = gr.Slider(
1091
+ minimum=0,
1092
+ maximum=1,
1093
+ label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
1094
+ value=1,
1095
+ interactive=True,
1096
+ )
1097
+ protect1 = gr.Slider(
1098
+ minimum=0,
1099
+ maximum=0.5,
1100
+ label=i18n(
1101
+ "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
1102
+ ),
1103
+ value=0.33,
1104
+ step=0.01,
1105
+ interactive=True,
1106
+ )
1107
+ with gr.Column():
1108
+ dir_input = gr.Textbox(
1109
+ label=i18n("输入待处理音频文件夹路径(去文件管理器地址栏拷就行了)"),
1110
+ value="E:\codes\py39\\test-20230416b\\todo-songs",
1111
+ )
1112
+ inputs = gr.File(
1113
+ file_count="multiple", label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹")
1114
+ )
1115
+ with gr.Row():
1116
+ format1 = gr.Radio(
1117
+ label=i18n("导出文件格式"),
1118
+ choices=["wav", "flac", "mp3", "m4a"],
1119
+ value="flac",
1120
+ interactive=True,
1121
+ )
1122
+ but1 = gr.Button(i18n("转换"), variant="primary")
1123
+ vc_output3 = gr.Textbox(label=i18n("输出信息"))
1124
+ but1.click(
1125
+ vc.vc_multi,
1126
+ [
1127
+ spk_item,
1128
+ dir_input,
1129
+ opt_input,
1130
+ inputs,
1131
+ vc_transform1,
1132
+ f0method1,
1133
+ file_index3,
1134
+ file_index4,
1135
+ # file_big_npy2,
1136
+ index_rate2,
1137
+ filter_radius1,
1138
+ resample_sr1,
1139
+ rms_mix_rate1,
1140
+ protect1,
1141
+ format1,
1142
+ ],
1143
+ [vc_output3],
1144
+ api_name="infer_convert_batch",
1145
+ )
1146
+ sid0.change(
1147
+ fn=vc.get_vc,
1148
+ inputs=[sid0, protect0, protect1],
1149
+ outputs=[spk_item, protect0, protect1, file_index2, file_index4],
1150
+ )
1151
+ with gr.TabItem("Download Model"):
1152
+ with gr.Row():
1153
+ url=gr.Textbox(label="Enter the URL to the Model:")
1154
+ with gr.Row():
1155
+ model = gr.Textbox(label="Name your model:")
1156
+ download_button=gr.Button("Download")
1157
+ with gr.Row():
1158
+ status_bar=gr.Textbox(label="")
1159
+ download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
1160
+ with gr.Row():
1161
+ gr.Markdown(
1162
+ """
1163
+ ❤️ If you like the EasyGUI, help me keep it.❤️
1164
+ https://paypal.me/lesantillan
1165
+ """
1166
+ )
1167
+ with gr.TabItem(i18n("训练")):
1168
+ with gr.Row():
1169
+ with gr.Column():
1170
+ exp_dir1 = gr.Textbox(label=i18n("输入实验名"), value="My-Voice")
1171
+ np7 = gr.Slider(
1172
+ minimum=0,
1173
+ maximum=config.n_cpu,
1174
+ step=1,
1175
+ label=i18n("提取音高和处理数据使用的CPU进程数"),
1176
+ value=int(np.ceil(config.n_cpu / 1.5)),
1177
+ interactive=True,
1178
+ )
1179
+ sr2 = gr.Radio(
1180
+ label=i18n("目标采样率"),
1181
+ choices=["40k", "48k"],
1182
+ value="40k",
1183
+ interactive=True,
1184
+ visible=False
1185
+ )
1186
+ if_f0_3 = gr.Radio(
1187
+ label=i18n("模型是否带音高指导(唱歌一定要, 语音可以不要)"),
1188
+ choices=[True, False],
1189
+ value=True,
1190
+ interactive=True,
1191
+ visible=False
1192
+ )
1193
+ version19 = gr.Radio(
1194
+ label=i18n("版本"),
1195
+ choices=["v1", "v2"],
1196
+ value="v2",
1197
+ interactive=True,
1198
+ visible=False,
1199
+ )
1200
+ trainset_dir4 = gr.Textbox(
1201
+ label=i18n("输入训练文件夹路径"), value='./dataset/'+datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
1202
+ )
1203
+ easy_uploader = gr.Files(label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹"),file_types=['audio'])
1204
+ but1 = gr.Button(label=i18n("处理数据"), variant="primary")
1205
+ info1 = gr.Textbox(label=i18n("输出信息"), value="")
1206
+ easy_uploader.upload(fn=upload_to_dataset, inputs=[easy_uploader, trainset_dir4], outputs=[info1, trainset_dir4])
1207
+ gpus6 = gr.Textbox(
1208
+ label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1209
+ value=gpus,
1210
+ interactive=True,
1211
+ visible=F0GPUVisible,
1212
+ )
1213
+ gpu_info9 = gr.Textbox(
1214
+ label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
1215
+ )
1216
+ spk_id5 = gr.Slider(
1217
+ minimum=0,
1218
+ maximum=4,
1219
+ step=1,
1220
+ label=i18n("请指定说话人id"),
1221
+ value=0,
1222
+ interactive=True,
1223
+ visible=False
1224
+ )
1225
+ but1.click(
1226
+ preprocess_dataset,
1227
+ [trainset_dir4, exp_dir1, sr2, np7],
1228
+ [info1],
1229
+ api_name="train_preprocess",
1230
+ )
1231
+ with gr.Column():
1232
+ f0method8 = gr.Radio(
1233
+ label=i18n(
1234
+ "选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢,rmvpe效果最好且微吃CPU/GPU"
1235
+ ),
1236
+ choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
1237
+ value="rmvpe_gpu",
1238
+ interactive=True,
1239
+ )
1240
+ gpus_rmvpe = gr.Textbox(
1241
+ label=i18n(
1242
+ "rmvpe卡号配置:以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"
1243
+ ),
1244
+ value="%s-%s" % (gpus, gpus),
1245
+ interactive=True,
1246
+ visible=F0GPUVisible,
1247
+ )
1248
+ but2 = gr.Button(i18n("特征提取"), variant="primary")
1249
+ info2 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1250
+ f0method8.change(
1251
+ fn=change_f0_method,
1252
+ inputs=[f0method8],
1253
+ outputs=[gpus_rmvpe],
1254
+ )
1255
+ but2.click(
1256
+ extract_f0_feature,
1257
+ [
1258
+ gpus6,
1259
+ np7,
1260
+ f0method8,
1261
+ if_f0_3,
1262
+ exp_dir1,
1263
+ version19,
1264
+ gpus_rmvpe,
1265
+ ],
1266
+ [info2],
1267
+ api_name="train_extract_f0_feature",
1268
+ )
1269
+ with gr.Column():
1270
+ total_epoch11 = gr.Slider(
1271
+ minimum=2,
1272
+ maximum=1000,
1273
+ step=1,
1274
+ label=i18n("总训练轮数total_epoch"),
1275
+ value=150,
1276
+ interactive=True,
1277
+ )
1278
+ gpus16 = gr.Textbox(
1279
+ label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1280
+ value="0",
1281
+ interactive=True,
1282
+ visible=True
1283
+ )
1284
+ but3 = gr.Button(i18n("训练模型"), variant="primary")
1285
+ but4 = gr.Button(i18n("训练特征索引"), variant="primary")
1286
+ info3 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=10)
1287
+ with gr.Accordion(label=i18n("常规设置"), open=False):
1288
+ save_epoch10 = gr.Slider(
1289
+ minimum=1,
1290
+ maximum=50,
1291
+ step=1,
1292
+ label=i18n("保存频率save_every_epoch"),
1293
+ value=25,
1294
+ interactive=True,
1295
+ )
1296
+ batch_size12 = gr.Slider(
1297
+ minimum=1,
1298
+ maximum=40,
1299
+ step=1,
1300
+ label=i18n("每张显卡的batch_size"),
1301
+ value=default_batch_size,
1302
+ interactive=True,
1303
+ )
1304
+ if_save_latest13 = gr.Radio(
1305
+ label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"),
1306
+ choices=[i18n("是"), i18n("否")],
1307
+ value=i18n("是"),
1308
+ interactive=True,
1309
+ )
1310
+ if_cache_gpu17 = gr.Radio(
1311
+ label=i18n(
1312
+ "是否缓存所有训练集至显存. 10min以下小数据可缓存以加速训练, 大数据缓存会炸显存也加不了多少速"
1313
+ ),
1314
+ choices=[i18n("是"), i18n("否")],
1315
+ value=i18n("否"),
1316
+ interactive=True,
1317
+ )
1318
+ if_save_every_weights18 = gr.Radio(
1319
+ label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"),
1320
+ choices=[i18n("是"), i18n("否")],
1321
+ value=i18n("是"),
1322
+ interactive=True,
1323
+ )
1324
+ with gr.Row():
1325
+ pretrained_G14 = gr.Textbox(
1326
+ label=i18n("加载预训练底模G路径"),
1327
+ value="assets/pretrained_v2/f0G40k.pth",
1328
+ interactive=True,
1329
+ visible=False
1330
+ )
1331
+ pretrained_D15 = gr.Textbox(
1332
+ label=i18n("加载预训练底模D路径"),
1333
+ value="assets/pretrained_v2/f0D40k.pth",
1334
+ interactive=True,
1335
+ visible=False
1336
+ )
1337
+ sr2.change(
1338
+ change_sr2,
1339
+ [sr2, if_f0_3, version19],
1340
+ [pretrained_G14, pretrained_D15],
1341
+ )
1342
+ version19.change(
1343
+ change_version19,
1344
+ [sr2, if_f0_3, version19],
1345
+ [pretrained_G14, pretrained_D15, sr2],
1346
+ )
1347
+ if_f0_3.change(
1348
+ change_f0,
1349
+ [if_f0_3, sr2, version19],
1350
+ [f0method8, pretrained_G14, pretrained_D15],
1351
+ )
1352
+ with gr.Row():
1353
+ but5 = gr.Button(i18n("一键训练"), variant="primary", visible=False)
1354
+ but3.click(
1355
+ click_train,
1356
+ [
1357
+ exp_dir1,
1358
+ sr2,
1359
+ if_f0_3,
1360
+ spk_id5,
1361
+ save_epoch10,
1362
+ total_epoch11,
1363
+ batch_size12,
1364
+ if_save_latest13,
1365
+ pretrained_G14,
1366
+ pretrained_D15,
1367
+ gpus16,
1368
+ if_cache_gpu17,
1369
+ if_save_every_weights18,
1370
+ version19,
1371
+ ],
1372
+ info3,
1373
+ api_name="train_start",
1374
+ )
1375
+ but4.click(train_index, [exp_dir1, version19], info3)
1376
+ but5.click(
1377
+ train1key,
1378
+ [
1379
+ exp_dir1,
1380
+ sr2,
1381
+ if_f0_3,
1382
+ trainset_dir4,
1383
+ spk_id5,
1384
+ np7,
1385
+ f0method8,
1386
+ save_epoch10,
1387
+ total_epoch11,
1388
+ batch_size12,
1389
+ if_save_latest13,
1390
+ pretrained_G14,
1391
+ pretrained_D15,
1392
+ gpus16,
1393
+ if_cache_gpu17,
1394
+ if_save_every_weights18,
1395
+ version19,
1396
+ gpus_rmvpe,
1397
+ ],
1398
+ info3,
1399
+ api_name="train_start_all",
1400
+ )
1401
+
1402
+ if config.iscolab:
1403
+ app.queue(concurrency_count=511, max_size=1022).launch(share=True)
1404
+ else:
1405
+ app.queue(concurrency_count=511, max_size=1022).launch(
1406
+ server_name="0.0.0.0",
1407
+ inbrowser=not config.noautoopen,
1408
+ server_port=config.listen_port,
1409
+ quiet=True,
1410
+ )
LICENSE ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 liujing04
4
+ Copyright (c) 2023 源文雨
5
+ Copyright (c) 2023 Ftps
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
MIT协议暨相关引用库协议 ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 本软件及其相关代码以MIT协议开源,作者不对软件具备任何控制力,使用软件者、传播软件导出的声音者自负全责。
2
+ 如不认可该条款,则不能使用或引用软件包内任何代码和文件。
3
+
4
+ 特此授予任何获得本软件和相关文档文件(以下简称“软件”)副本的人免费使用、复制、修改、合并、出版、分发、再授权和/或销售本软件的权利,以及授予本软件所提供的人使用本软件的权利,但须符合以下条件:
5
+ 上述版权声明和本许可声明应包含在软件的所有副本或实质部分中。
6
+ 软件是“按原样”提供的,没有任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和不侵权的保证。在任何情况下,作者或版权持有人均不承担因软件或软件的使用或其他交易而产生、产生或与之相关的任何索赔、损害赔偿或其他责任,无论是在合同诉讼、侵权诉讼还是其他诉讼中。
7
+
8
+
9
+ The LICENCEs for related libraries are as follows.
10
+ 相关引用库协议如下:
11
+
12
+ ContentVec
13
+ https://github.com/auspicious3000/contentvec/blob/main/LICENSE
14
+ MIT License
15
+
16
+ VITS
17
+ https://github.com/jaywalnut310/vits/blob/main/LICENSE
18
+ MIT License
19
+
20
+ HIFIGAN
21
+ https://github.com/jik876/hifi-gan/blob/master/LICENSE
22
+ MIT License
23
+
24
+ gradio
25
+ https://github.com/gradio-app/gradio/blob/main/LICENSE
26
+ Apache License 2.0
27
+
28
+ ffmpeg
29
+ https://github.com/FFmpeg/FFmpeg/blob/master/COPYING.LGPLv3
30
+ https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2021-02-28-12-32/ffmpeg-n4.3.2-160-gfbb9368226-win64-lgpl-4.3.zip
31
+ LPGLv3 License
32
+ MIT License
33
+
34
+ ultimatevocalremovergui
35
+ https://github.com/Anjok07/ultimatevocalremovergui/blob/master/LICENSE
36
+ https://github.com/yang123qwe/vocal_separation_by_uvr5
37
+ MIT License
38
+
39
+ audio-slicer
40
+ https://github.com/openvpi/audio-slicer/blob/main/LICENSE
41
+ MIT License
42
+
43
+ PySimpleGUI
44
+ https://github.com/PySimpleGUI/PySimpleGUI/blob/master/license.txt
45
+ LPGLv3 License
README.md CHANGED
@@ -1,12 +1,38 @@
1
  ---
2
- title: Project Main
3
- emoji: 🏃
4
- colorFrom: green
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 3.47.1
8
- app_file: app.py
9
- pinned: false
10
  ---
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: project-main
3
+ app_file: infer-web.py
 
 
4
  sdk: gradio
5
+ sdk_version: 3.43.2
 
 
6
  ---
7
+ [![Open In Colab](https://img.shields.io/badge/Colab-F9AB00?style=for-the-badge&logo=googlecolab&color=525252)](https://colab.research.google.com/drive/1r4IRL0UA7JEoZ0ZK8PKfMyTIBHKpyhcw)
8
 
9
+ # Local Installation
10
+ If you already have RVC installed, then just download GUI.py and drop it in the root folder!
11
+ If you need to install RVC, I recommend you check the [original repo](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI)
12
+ Or read this at least.
13
+
14
+ I recommend you use a virtual environment
15
+
16
+ ```bash
17
+ python -m venv RVC
18
+ cd RVC
19
+ git clone https://github.com/777gt/-EVC-
20
+ Scripts/activate.bat
21
+ pip install torch torchvision torchaudio
22
+ pip install -r "-EVC-/requirements.txt"
23
+ ```
24
+ If you're on Windows, like me, and don't have an NVIDA graphics card, install the requirements from a different .txt:
25
+ ```bash
26
+ pip install -r "-EVC-/requirements-dml.txt"
27
+ ```
28
+ Also, do not forget to download the necessary models. EasyGUI uses RVC 2 40k models.
29
+
30
+ ```bash
31
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/rmvpe.pt -O ./assets/rmvpe/rmvpe.pt
32
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/rmvpe.onnx -O ./assets/rmvpe/rmvpe.onnx
33
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt -O ./assets/hubert/hubert_base.pt
34
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/D40k.pth -O ./assets/pretrained_v2/D40k.pth
35
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/G40k.pth -O ./assets/pretrained_v2/G40k.pth
36
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0D40k.pth -O ./assets/pretrained_v2/f0D40k.pth
37
+ wget https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0G40k.pth -O ./assets/pretrained_v2/f0G40k.pth
38
+ ```
Retrieval_based_Voice_Conversion_WebUI.ipynb ADDED
@@ -0,0 +1,403 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "# [Retrieval-based-Voice-Conversion-WebUI](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI) Training notebook"
9
+ ]
10
+ },
11
+ {
12
+ "attachments": {},
13
+ "cell_type": "markdown",
14
+ "metadata": {
15
+ "id": "ZFFCx5J80SGa"
16
+ },
17
+ "source": [
18
+ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/blob/main/Retrieval_based_Voice_Conversion_WebUI.ipynb)"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "metadata": {
25
+ "id": "GmFP6bN9dvOq"
26
+ },
27
+ "outputs": [],
28
+ "source": [
29
+ "# @title 查看显卡\n",
30
+ "!nvidia-smi"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": null,
36
+ "metadata": {
37
+ "id": "jwu07JgqoFON"
38
+ },
39
+ "outputs": [],
40
+ "source": [
41
+ "# @title 挂载谷歌云盘\n",
42
+ "\n",
43
+ "from google.colab import drive\n",
44
+ "\n",
45
+ "drive.mount(\"/content/drive\")"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "metadata": {
52
+ "id": "wjddIFr1oS3W"
53
+ },
54
+ "outputs": [],
55
+ "source": [
56
+ "# @title 安装依赖\n",
57
+ "!apt-get -y install build-essential python3-dev ffmpeg\n",
58
+ "!pip3 install --upgrade setuptools wheel\n",
59
+ "!pip3 install --upgrade pip\n",
60
+ "!pip3 install faiss-cpu==1.7.2 fairseq gradio==3.14.0 ffmpeg ffmpeg-python praat-parselmouth pyworld numpy==1.23.5 numba==0.56.4 librosa==0.9.2"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": null,
66
+ "metadata": {
67
+ "id": "ge_97mfpgqTm"
68
+ },
69
+ "outputs": [],
70
+ "source": [
71
+ "# @title 克隆仓库\n",
72
+ "\n",
73
+ "!git clone --depth=1 -b stable https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI\n",
74
+ "%cd /content/Retrieval-based-Voice-Conversion-WebUI\n",
75
+ "!mkdir -p pretrained uvr5_weights"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": null,
81
+ "metadata": {
82
+ "id": "BLDEZADkvlw1"
83
+ },
84
+ "outputs": [],
85
+ "source": [
86
+ "# @title 更新仓库(一般无需执行)\n",
87
+ "!git pull"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": null,
93
+ "metadata": {
94
+ "id": "pqE0PrnuRqI2"
95
+ },
96
+ "outputs": [],
97
+ "source": [
98
+ "# @title 安装aria2\n",
99
+ "!apt -y install -qq aria2"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": null,
105
+ "metadata": {
106
+ "id": "UG3XpUwEomUz"
107
+ },
108
+ "outputs": [],
109
+ "source": [
110
+ "# @title 下载底模\n",
111
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D32k.pth\n",
112
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D40k.pth\n",
113
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D48k.pth\n",
114
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G32k.pth\n",
115
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G40k.pth\n",
116
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G48k.pth\n",
117
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D32k.pth\n",
118
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D40k.pth\n",
119
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D48k.pth\n",
120
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G32k.pth\n",
121
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G40k.pth\n",
122
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G48k.pth"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": null,
128
+ "metadata": {
129
+ "id": "HugjmZqZRuiF"
130
+ },
131
+ "outputs": [],
132
+ "source": [
133
+ "# @title 下载人声分离模型\n",
134
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP2-人声vocals+非人声instrumentals.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/uvr5_weights -o HP2-人声vocals+非人声instrumentals.pth\n",
135
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP5-主旋律人声vocals+其他instrumentals.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/uvr5_weights -o HP5-主旋律人声vocals+其他instrumentals.pth"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "code",
140
+ "execution_count": null,
141
+ "metadata": {
142
+ "id": "2RCaT9FTR0ej"
143
+ },
144
+ "outputs": [],
145
+ "source": [
146
+ "# @title 下载hubert_base\n",
147
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt -d /content/Retrieval-based-Voice-Conversion-WebUI -o hubert_base.pt"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": null,
153
+ "metadata": {},
154
+ "outputs": [],
155
+ "source": [
156
+ "# @title #下载rmvpe模型\n",
157
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/rmvpe.pt -d /content/Retrieval-based-Voice-Conversion-WebUI -o rmvpe.pt"
158
+ ]
159
+ },
160
+ {
161
+ "cell_type": "code",
162
+ "execution_count": null,
163
+ "metadata": {
164
+ "id": "Mwk7Q0Loqzjx"
165
+ },
166
+ "outputs": [],
167
+ "source": [
168
+ "# @title 从谷歌云盘加载打包好的数据集到/content/dataset\n",
169
+ "\n",
170
+ "# @markdown 数据集位置\n",
171
+ "DATASET = (\n",
172
+ " \"/content/drive/MyDrive/dataset/lulu20230327_32k.zip\" # @param {type:\"string\"}\n",
173
+ ")\n",
174
+ "\n",
175
+ "!mkdir -p /content/dataset\n",
176
+ "!unzip -d /content/dataset -B {DATASET}"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": null,
182
+ "metadata": {
183
+ "id": "PDlFxWHWEynD"
184
+ },
185
+ "outputs": [],
186
+ "source": [
187
+ "# @title 重命名数据集中的重名文件\n",
188
+ "!ls -a /content/dataset/\n",
189
+ "!rename 's/(\\w+)\\.(\\w+)~(\\d*)/$1_$3.$2/' /content/dataset/*.*~*"
190
+ ]
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "execution_count": null,
195
+ "metadata": {
196
+ "id": "7vh6vphDwO0b"
197
+ },
198
+ "outputs": [],
199
+ "source": [
200
+ "# @title 启动web\n",
201
+ "%cd /content/Retrieval-based-Voice-Conversion-WebUI\n",
202
+ "# %load_ext tensorboard\n",
203
+ "# %tensorboard --logdir /content/Retrieval-based-Voice-Conversion-WebUI/logs\n",
204
+ "!python3 infer-web.py --colab --pycmd python3"
205
+ ]
206
+ },
207
+ {
208
+ "cell_type": "code",
209
+ "execution_count": null,
210
+ "metadata": {
211
+ "id": "FgJuNeAwx5Y_"
212
+ },
213
+ "outputs": [],
214
+ "source": [
215
+ "# @title 手动将训练后的模型文件备份到谷歌云盘\n",
216
+ "# @markdown 需要自己查看logs文件夹下模型的文件名,手动修改下方命令末尾的文件名\n",
217
+ "\n",
218
+ "# @markdown 模型名\n",
219
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
220
+ "# @markdown 模型epoch\n",
221
+ "MODELEPOCH = 9600 # @param {type:\"integer\"}\n",
222
+ "\n",
223
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/drive/MyDrive/{MODELNAME}_D_{MODELEPOCH}.pth\n",
224
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/drive/MyDrive/{MODELNAME}_G_{MODELEPOCH}.pth\n",
225
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/added_*.index /content/drive/MyDrive/\n",
226
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/total_*.npy /content/drive/MyDrive/\n",
227
+ "\n",
228
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/weights/{MODELNAME}.pth /content/drive/MyDrive/{MODELNAME}{MODELEPOCH}.pth"
229
+ ]
230
+ },
231
+ {
232
+ "cell_type": "code",
233
+ "execution_count": null,
234
+ "metadata": {
235
+ "id": "OVQoLQJXS7WX"
236
+ },
237
+ "outputs": [],
238
+ "source": [
239
+ "# @title 从谷歌云盘恢复pth\n",
240
+ "# @markdown 需要自己查看logs文件夹下模型的文件名,手动修改下方命令末尾的文件名\n",
241
+ "\n",
242
+ "# @markdown 模型名\n",
243
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
244
+ "# @markdown 模型epoch\n",
245
+ "MODELEPOCH = 7500 # @param {type:\"integer\"}\n",
246
+ "\n",
247
+ "!mkdir -p /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",
248
+ "\n",
249
+ "!cp /content/drive/MyDrive/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",
250
+ "!cp /content/drive/MyDrive/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",
251
+ "!cp /content/drive/MyDrive/*.index /content/\n",
252
+ "!cp /content/drive/MyDrive/*.npy /content/\n",
253
+ "!cp /content/drive/MyDrive/{MODELNAME}{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/weights/{MODELNAME}.pth"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "execution_count": null,
259
+ "metadata": {
260
+ "id": "ZKAyuKb9J6dz"
261
+ },
262
+ "outputs": [],
263
+ "source": [
264
+ "# @title 手动预处理(不推荐)\n",
265
+ "# @markdown 模型名\n",
266
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
267
+ "# @markdown 采样率\n",
268
+ "BITRATE = 48000 # @param {type:\"integer\"}\n",
269
+ "# @markdown 使用的进程数\n",
270
+ "THREADCOUNT = 8 # @param {type:\"integer\"}\n",
271
+ "\n",
272
+ "!python3 trainset_preprocess_pipeline_print.py /content/dataset {BITRATE} {THREADCOUNT} logs/{MODELNAME} True"
273
+ ]
274
+ },
275
+ {
276
+ "cell_type": "code",
277
+ "execution_count": null,
278
+ "metadata": {
279
+ "id": "CrxJqzAUKmPJ"
280
+ },
281
+ "outputs": [],
282
+ "source": [
283
+ "# @title 手动提取特征(不推荐)\n",
284
+ "# @markdown 模型名\n",
285
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
286
+ "# @markdown 使用的进程数\n",
287
+ "THREADCOUNT = 8 # @param {type:\"integer\"}\n",
288
+ "# @markdown 音高提取算法\n",
289
+ "ALGO = \"harvest\" # @param {type:\"string\"}\n",
290
+ "\n",
291
+ "!python3 extract_f0_print.py logs/{MODELNAME} {THREADCOUNT} {ALGO}\n",
292
+ "\n",
293
+ "!python3 extract_feature_print.py cpu 1 0 0 logs/{MODELNAME}"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "execution_count": null,
299
+ "metadata": {
300
+ "id": "IMLPLKOaKj58"
301
+ },
302
+ "outputs": [],
303
+ "source": [
304
+ "# @title 手动训练(不推荐)\n",
305
+ "# @markdown 模型名\n",
306
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
307
+ "# @markdown 使用的GPU\n",
308
+ "USEGPU = \"0\" # @param {type:\"string\"}\n",
309
+ "# @markdown 批大小\n",
310
+ "BATCHSIZE = 32 # @param {type:\"integer\"}\n",
311
+ "# @markdown 停止的epoch\n",
312
+ "MODELEPOCH = 3200 # @param {type:\"integer\"}\n",
313
+ "# @markdown 保存epoch间隔\n",
314
+ "EPOCHSAVE = 100 # @param {type:\"integer\"}\n",
315
+ "# @markdown 采样率\n",
316
+ "MODELSAMPLE = \"48k\" # @param {type:\"string\"}\n",
317
+ "# @markdown 是否缓存训练集\n",
318
+ "CACHEDATA = 1 # @param {type:\"integer\"}\n",
319
+ "# @markdown 是否仅保存最新的ckpt文件\n",
320
+ "ONLYLATEST = 0 # @param {type:\"integer\"}\n",
321
+ "\n",
322
+ "!python3 train_nsf_sim_cache_sid_load_pretrain.py -e lulu -sr {MODELSAMPLE} -f0 1 -bs {BATCHSIZE} -g {USEGPU} -te {MODELEPOCH} -se {EPOCHSAVE} -pg pretrained/f0G{MODELSAMPLE}.pth -pd pretrained/f0D{MODELSAMPLE}.pth -l {ONLYLATEST} -c {CACHEDATA}"
323
+ ]
324
+ },
325
+ {
326
+ "cell_type": "code",
327
+ "execution_count": null,
328
+ "metadata": {
329
+ "id": "haYA81hySuDl"
330
+ },
331
+ "outputs": [],
332
+ "source": [
333
+ "# @title 删除其它pth,只留选中的(慎点,仔细看代码)\n",
334
+ "# @markdown 模型名\n",
335
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
336
+ "# @markdown 选中模型epoch\n",
337
+ "MODELEPOCH = 9600 # @param {type:\"integer\"}\n",
338
+ "\n",
339
+ "!echo \"备份选中的模型。。。\"\n",
340
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/{MODELNAME}_D_{MODELEPOCH}.pth\n",
341
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/{MODELNAME}_G_{MODELEPOCH}.pth\n",
342
+ "\n",
343
+ "!echo \"正在删除。。。\"\n",
344
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",
345
+ "!rm /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/*.pth\n",
346
+ "\n",
347
+ "!echo \"恢复选中的模型。。。\"\n",
348
+ "!mv /content/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",
349
+ "!mv /content/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",
350
+ "\n",
351
+ "!echo \"删除完成\"\n",
352
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}"
353
+ ]
354
+ },
355
+ {
356
+ "cell_type": "code",
357
+ "execution_count": null,
358
+ "metadata": {
359
+ "id": "QhSiPTVPoIRh"
360
+ },
361
+ "outputs": [],
362
+ "source": [
363
+ "# @title 清除项目下所有文件,只留选中的模型(慎点,仔细看代码)\n",
364
+ "# @markdown 模型名\n",
365
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
366
+ "# @markdown 选中模型epoch\n",
367
+ "MODELEPOCH = 9600 # @param {type:\"integer\"}\n",
368
+ "\n",
369
+ "!echo \"备份选中的模型。。。\"\n",
370
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/{MODELNAME}_D_{MODELEPOCH}.pth\n",
371
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/{MODELNAME}_G_{MODELEPOCH}.pth\n",
372
+ "\n",
373
+ "!echo \"正��删除。。。\"\n",
374
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",
375
+ "!rm -rf /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/*\n",
376
+ "\n",
377
+ "!echo \"恢复选中的模型。。。\"\n",
378
+ "!mv /content/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",
379
+ "!mv /content/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",
380
+ "\n",
381
+ "!echo \"删除完成\"\n",
382
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}"
383
+ ]
384
+ }
385
+ ],
386
+ "metadata": {
387
+ "accelerator": "GPU",
388
+ "colab": {
389
+ "private_outputs": true,
390
+ "provenance": []
391
+ },
392
+ "gpuClass": "standard",
393
+ "kernelspec": {
394
+ "display_name": "Python 3",
395
+ "name": "python3"
396
+ },
397
+ "language_info": {
398
+ "name": "python"
399
+ }
400
+ },
401
+ "nbformat": 4,
402
+ "nbformat_minor": 0
403
+ }
Retrieval_based_Voice_Conversion_WebUI_v2.ipynb ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "attachments": {},
5
+ "cell_type": "markdown",
6
+ "metadata": {},
7
+ "source": [
8
+ "# [Retrieval-based-Voice-Conversion-WebUI](https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI) Training notebook"
9
+ ]
10
+ },
11
+ {
12
+ "attachments": {},
13
+ "cell_type": "markdown",
14
+ "metadata": {
15
+ "id": "ZFFCx5J80SGa"
16
+ },
17
+ "source": [
18
+ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/RVC-Project/Retrieval-based-Voice-Conversion-WebUI/blob/main/Retrieval_based_Voice_Conversion_WebUI_v2.ipynb)"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "metadata": {
25
+ "id": "GmFP6bN9dvOq"
26
+ },
27
+ "outputs": [],
28
+ "source": [
29
+ "# @title #查看显卡\n",
30
+ "!nvidia-smi"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": null,
36
+ "metadata": {
37
+ "id": "jwu07JgqoFON"
38
+ },
39
+ "outputs": [],
40
+ "source": [
41
+ "# @title 挂载谷歌云盘\n",
42
+ "\n",
43
+ "from google.colab import drive\n",
44
+ "\n",
45
+ "drive.mount(\"/content/drive\")"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": null,
51
+ "metadata": {
52
+ "id": "wjddIFr1oS3W"
53
+ },
54
+ "outputs": [],
55
+ "source": [
56
+ "# @title #安装依赖\n",
57
+ "!apt-get -y install build-essential python3-dev ffmpeg\n",
58
+ "!pip3 install --upgrade setuptools wheel\n",
59
+ "!pip3 install --upgrade pip\n",
60
+ "!pip3 install faiss-cpu==1.7.2 fairseq gradio==3.14.0 ffmpeg ffmpeg-python praat-parselmouth pyworld numpy==1.23.5 numba==0.56.4 librosa==0.9.2"
61
+ ]
62
+ },
63
+ {
64
+ "cell_type": "code",
65
+ "execution_count": null,
66
+ "metadata": {
67
+ "id": "ge_97mfpgqTm"
68
+ },
69
+ "outputs": [],
70
+ "source": [
71
+ "# @title #克隆仓库\n",
72
+ "\n",
73
+ "!mkdir Retrieval-based-Voice-Conversion-WebUI\n",
74
+ "%cd /content/Retrieval-based-Voice-Conversion-WebUI\n",
75
+ "!git init\n",
76
+ "!git remote add origin https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git\n",
77
+ "!git fetch origin cfd984812804ddc9247d65b14c82cd32e56c1133 --depth=1\n",
78
+ "!git reset --hard FETCH_HEAD"
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "execution_count": null,
84
+ "metadata": {
85
+ "id": "BLDEZADkvlw1"
86
+ },
87
+ "outputs": [],
88
+ "source": [
89
+ "# @title #更新仓库(一般无需执行)\n",
90
+ "!git pull"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": null,
96
+ "metadata": {
97
+ "id": "pqE0PrnuRqI2"
98
+ },
99
+ "outputs": [],
100
+ "source": [
101
+ "# @title #安装aria2\n",
102
+ "!apt -y install -qq aria2"
103
+ ]
104
+ },
105
+ {
106
+ "cell_type": "code",
107
+ "execution_count": null,
108
+ "metadata": {
109
+ "id": "UG3XpUwEomUz"
110
+ },
111
+ "outputs": [],
112
+ "source": [
113
+ "# @title 下载底模\n",
114
+ "\n",
115
+ "# v1\n",
116
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D32k.pth\n",
117
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D40k.pth\n",
118
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o D48k.pth\n",
119
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G32k.pth\n",
120
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G40k.pth\n",
121
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o G48k.pth\n",
122
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D32k.pth\n",
123
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D40k.pth\n",
124
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0D48k.pth\n",
125
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G32k.pth\n",
126
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G40k.pth\n",
127
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained/f0G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained -o f0G48k.pth\n",
128
+ "\n",
129
+ "# v2\n",
130
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o D32k.pth\n",
131
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o D40k.pth\n",
132
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o D48k.pth\n",
133
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o G32k.pth\n",
134
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o G40k.pth\n",
135
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o G48k.pth\n",
136
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0D32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o f0D32k.pth\n",
137
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0D40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o f0D40k.pth\n",
138
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0D48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o f0D48k.pth\n",
139
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0G32k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o f0G32k.pth\n",
140
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0G40k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o f0G40k.pth\n",
141
+ "# !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/pretrained_v2/f0G48k.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/pretrained_v2 -o f0G48k.pth"
142
+ ]
143
+ },
144
+ {
145
+ "cell_type": "code",
146
+ "execution_count": null,
147
+ "metadata": {
148
+ "id": "HugjmZqZRuiF"
149
+ },
150
+ "outputs": [],
151
+ "source": [
152
+ "# @title #下载人声分离模型\n",
153
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP2-人声vocals+非人声instrumentals.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/uvr5_weights -o HP2-人声vocals+非人声instrumentals.pth\n",
154
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/uvr5_weights/HP5-主旋律人声vocals+其他instrumentals.pth -d /content/Retrieval-based-Voice-Conversion-WebUI/uvr5_weights -o HP5-主旋律人声vocals+其他instrumentals.pth"
155
+ ]
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "execution_count": null,
160
+ "metadata": {
161
+ "id": "2RCaT9FTR0ej"
162
+ },
163
+ "outputs": [],
164
+ "source": [
165
+ "# @title #下载hubert_base\n",
166
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/hubert_base.pt -d /content/Retrieval-based-Voice-Conversion-WebUI -o hubert_base.pt"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "execution_count": null,
172
+ "metadata": {},
173
+ "outputs": [],
174
+ "source": [
175
+ "# @title #下载rmvpe模型\n",
176
+ "!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lj1995/VoiceConversionWebUI/resolve/main/rmvpe.pt -d /content/Retrieval-based-Voice-Conversion-WebUI -o rmvpe.pt"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": null,
182
+ "metadata": {
183
+ "id": "Mwk7Q0Loqzjx"
184
+ },
185
+ "outputs": [],
186
+ "source": [
187
+ "# @title #从谷歌云盘加载打包好的数据集到/content/dataset\n",
188
+ "\n",
189
+ "# @markdown 数据集位置\n",
190
+ "DATASET = (\n",
191
+ " \"/content/drive/MyDrive/dataset/lulu20230327_32k.zip\" # @param {type:\"string\"}\n",
192
+ ")\n",
193
+ "\n",
194
+ "!mkdir -p /content/dataset\n",
195
+ "!unzip -d /content/dataset -B {DATASET}"
196
+ ]
197
+ },
198
+ {
199
+ "cell_type": "code",
200
+ "execution_count": null,
201
+ "metadata": {
202
+ "id": "PDlFxWHWEynD"
203
+ },
204
+ "outputs": [],
205
+ "source": [
206
+ "# @title #重命名数据集中的重名文件\n",
207
+ "!ls -a /content/dataset/\n",
208
+ "!rename 's/(\\w+)\\.(\\w+)~(\\d*)/$1_$3.$2/' /content/dataset/*.*~*"
209
+ ]
210
+ },
211
+ {
212
+ "cell_type": "code",
213
+ "execution_count": null,
214
+ "metadata": {
215
+ "id": "7vh6vphDwO0b"
216
+ },
217
+ "outputs": [],
218
+ "source": [
219
+ "# @title #启动webui\n",
220
+ "%cd /content/Retrieval-based-Voice-Conversion-WebUI\n",
221
+ "# %load_ext tensorboard\n",
222
+ "# %tensorboard --logdir /content/Retrieval-based-Voice-Conversion-WebUI/logs\n",
223
+ "!python3 infer-web.py --colab --pycmd python3"
224
+ ]
225
+ },
226
+ {
227
+ "cell_type": "code",
228
+ "execution_count": null,
229
+ "metadata": {
230
+ "id": "FgJuNeAwx5Y_"
231
+ },
232
+ "outputs": [],
233
+ "source": [
234
+ "# @title #手动将训练后的模型文件备份到谷歌云盘\n",
235
+ "# @markdown #需要自己查看logs文件夹下模型的文件名,手动修改下方命令末尾的文件名\n",
236
+ "\n",
237
+ "# @markdown #模型名\n",
238
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
239
+ "# @markdown #模型epoch\n",
240
+ "MODELEPOCH = 9600 # @param {type:\"integer\"}\n",
241
+ "\n",
242
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/drive/MyDrive/{MODELNAME}_D_{MODELEPOCH}.pth\n",
243
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/drive/MyDrive/{MODELNAME}_G_{MODELEPOCH}.pth\n",
244
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/added_*.index /content/drive/MyDrive/\n",
245
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/total_*.npy /content/drive/MyDrive/\n",
246
+ "\n",
247
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/weights/{MODELNAME}.pth /content/drive/MyDrive/{MODELNAME}{MODELEPOCH}.pth"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": null,
253
+ "metadata": {
254
+ "id": "OVQoLQJXS7WX"
255
+ },
256
+ "outputs": [],
257
+ "source": [
258
+ "# @title 从谷歌云盘恢复pth\n",
259
+ "# @markdown 需要自己查看logs文件夹下模型的文件名,手动修改下方命令末尾的文件名\n",
260
+ "\n",
261
+ "# @markdown 模型名\n",
262
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
263
+ "# @markdown 模型epoch\n",
264
+ "MODELEPOCH = 7500 # @param {type:\"integer\"}\n",
265
+ "\n",
266
+ "!mkdir -p /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",
267
+ "\n",
268
+ "!cp /content/drive/MyDrive/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",
269
+ "!cp /content/drive/MyDrive/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",
270
+ "!cp /content/drive/MyDrive/*.index /content/\n",
271
+ "!cp /content/drive/MyDrive/*.npy /content/\n",
272
+ "!cp /content/drive/MyDrive/{MODELNAME}{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/weights/{MODELNAME}.pth"
273
+ ]
274
+ },
275
+ {
276
+ "cell_type": "code",
277
+ "execution_count": null,
278
+ "metadata": {
279
+ "id": "ZKAyuKb9J6dz"
280
+ },
281
+ "outputs": [],
282
+ "source": [
283
+ "# @title 手动预处理(不推荐)\n",
284
+ "# @markdown 模型名\n",
285
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
286
+ "# @markdown 采样率\n",
287
+ "BITRATE = 48000 # @param {type:\"integer\"}\n",
288
+ "# @markdown 使用的进程数\n",
289
+ "THREADCOUNT = 8 # @param {type:\"integer\"}\n",
290
+ "\n",
291
+ "!python3 trainset_preprocess_pipeline_print.py /content/dataset {BITRATE} {THREADCOUNT} logs/{MODELNAME} True"
292
+ ]
293
+ },
294
+ {
295
+ "cell_type": "code",
296
+ "execution_count": null,
297
+ "metadata": {
298
+ "id": "CrxJqzAUKmPJ"
299
+ },
300
+ "outputs": [],
301
+ "source": [
302
+ "# @title 手动提取特征(不推荐)\n",
303
+ "# @markdown 模型名\n",
304
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
305
+ "# @markdown 使用的进程数\n",
306
+ "THREADCOUNT = 8 # @param {type:\"integer\"}\n",
307
+ "# @markdown 音高提取算法\n",
308
+ "ALGO = \"harvest\" # @param {type:\"string\"}\n",
309
+ "\n",
310
+ "!python3 extract_f0_print.py logs/{MODELNAME} {THREADCOUNT} {ALGO}\n",
311
+ "\n",
312
+ "!python3 extract_feature_print.py cpu 1 0 0 logs/{MODELNAME}"
313
+ ]
314
+ },
315
+ {
316
+ "cell_type": "code",
317
+ "execution_count": null,
318
+ "metadata": {
319
+ "id": "IMLPLKOaKj58"
320
+ },
321
+ "outputs": [],
322
+ "source": [
323
+ "# @title 手动训练(不推荐)\n",
324
+ "# @markdown 模型名\n",
325
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
326
+ "# @markdown 使用的GPU\n",
327
+ "USEGPU = \"0\" # @param {type:\"string\"}\n",
328
+ "# @markdown 批大小\n",
329
+ "BATCHSIZE = 32 # @param {type:\"integer\"}\n",
330
+ "# @markdown 停止的epoch\n",
331
+ "MODELEPOCH = 3200 # @param {type:\"integer\"}\n",
332
+ "# @markdown 保存epoch间隔\n",
333
+ "EPOCHSAVE = 100 # @param {type:\"integer\"}\n",
334
+ "# @markdown 采样率\n",
335
+ "MODELSAMPLE = \"48k\" # @param {type:\"string\"}\n",
336
+ "# @markdown 是否缓存训练集\n",
337
+ "CACHEDATA = 1 # @param {type:\"integer\"}\n",
338
+ "# @markdown 是否仅保存最新的ckpt文件\n",
339
+ "ONLYLATEST = 0 # @param {type:\"integer\"}\n",
340
+ "\n",
341
+ "!python3 train_nsf_sim_cache_sid_load_pretrain.py -e lulu -sr {MODELSAMPLE} -f0 1 -bs {BATCHSIZE} -g {USEGPU} -te {MODELEPOCH} -se {EPOCHSAVE} -pg pretrained/f0G{MODELSAMPLE}.pth -pd pretrained/f0D{MODELSAMPLE}.pth -l {ONLYLATEST} -c {CACHEDATA}"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "code",
346
+ "execution_count": null,
347
+ "metadata": {
348
+ "id": "haYA81hySuDl"
349
+ },
350
+ "outputs": [],
351
+ "source": [
352
+ "# @title 删除其它pth,只留选中的(慎点,仔细看代码)\n",
353
+ "# @markdown 模型名\n",
354
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
355
+ "# @markdown 选中模型epoch\n",
356
+ "MODELEPOCH = 9600 # @param {type:\"integer\"}\n",
357
+ "\n",
358
+ "!echo \"备份选中的模型。。。\"\n",
359
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/{MODELNAME}_D_{MODELEPOCH}.pth\n",
360
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/{MODELNAME}_G_{MODELEPOCH}.pth\n",
361
+ "\n",
362
+ "!echo \"正在删除。。。\"\n",
363
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",
364
+ "!rm /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/*.pth\n",
365
+ "\n",
366
+ "!echo \"恢复选中的模型。。。\"\n",
367
+ "!mv /content/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",
368
+ "!mv /content/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",
369
+ "\n",
370
+ "!echo \"删除完成\"\n",
371
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}"
372
+ ]
373
+ },
374
+ {
375
+ "cell_type": "code",
376
+ "execution_count": null,
377
+ "metadata": {
378
+ "id": "QhSiPTVPoIRh"
379
+ },
380
+ "outputs": [],
381
+ "source": [
382
+ "# @title 清除项目下所有文件,只留选中的模型(慎点,仔细看代码)\n",
383
+ "# @markdown 模型名\n",
384
+ "MODELNAME = \"lulu\" # @param {type:\"string\"}\n",
385
+ "# @markdown 选中模型epoch\n",
386
+ "MODELEPOCH = 9600 # @param {type:\"integer\"}\n",
387
+ "\n",
388
+ "!echo \"备份选中的模型。。。\"\n",
389
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth /content/{MODELNAME}_D_{MODELEPOCH}.pth\n",
390
+ "!cp /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth /content/{MODELNAME}_G_{MODELEPOCH}.pth\n",
391
+ "\n",
392
+ "!echo \"正在删除。。。\"\n",
393
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}\n",
394
+ "!rm -rf /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/*\n",
395
+ "\n",
396
+ "!echo \"恢复选中的模型。。。\"\n",
397
+ "!mv /content/{MODELNAME}_D_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/G_{MODELEPOCH}.pth\n",
398
+ "!mv /content/{MODELNAME}_G_{MODELEPOCH}.pth /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}/D_{MODELEPOCH}.pth\n",
399
+ "\n",
400
+ "!echo \"删除完成\"\n",
401
+ "!ls /content/Retrieval-based-Voice-Conversion-WebUI/logs/{MODELNAME}"
402
+ ]
403
+ }
404
+ ],
405
+ "metadata": {
406
+ "accelerator": "GPU",
407
+ "colab": {
408
+ "private_outputs": true,
409
+ "provenance": []
410
+ },
411
+ "gpuClass": "standard",
412
+ "kernelspec": {
413
+ "display_name": "Python 3",
414
+ "name": "python3"
415
+ },
416
+ "language_info": {
417
+ "name": "python"
418
+ }
419
+ },
420
+ "nbformat": 4,
421
+ "nbformat_minor": 0
422
+ }
a.png ADDED
app.py ADDED
@@ -0,0 +1,1441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, sys
2
+ import datetime, subprocess
3
+ from mega import Mega
4
+ now_dir = os.getcwd()
5
+ sys.path.append(now_dir)
6
+ import logging
7
+ import shutil
8
+ import threading
9
+ import traceback
10
+ import warnings
11
+ from random import shuffle
12
+ from subprocess import Popen
13
+ from time import sleep
14
+ import json
15
+ import pathlib
16
+
17
+ import fairseq
18
+ import faiss
19
+ import gradio as gr
20
+ import numpy as np
21
+ import torch
22
+ from dotenv import load_dotenv
23
+ from sklearn.cluster import MiniBatchKMeans
24
+
25
+ from configs.config import Config
26
+ from i18n.i18n import I18nAuto
27
+ from infer.lib.train.process_ckpt import (
28
+ change_info,
29
+ extract_small_model,
30
+ merge,
31
+ show_info,
32
+ )
33
+ from infer.modules.uvr5.modules import uvr
34
+ from infer.modules.vc.modules import VC
35
+ logging.getLogger("numba").setLevel(logging.WARNING)
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+ tmp = os.path.join(now_dir, "TEMP")
40
+ shutil.rmtree(tmp, ignore_errors=True)
41
+ shutil.rmtree("%s/runtime/Lib/site-packages/infer_pack" % (now_dir), ignore_errors=True)
42
+ shutil.rmtree("%s/runtime/Lib/site-packages/uvr5_pack" % (now_dir), ignore_errors=True)
43
+ os.makedirs(tmp, exist_ok=True)
44
+ os.makedirs(os.path.join(now_dir, "logs"), exist_ok=True)
45
+ os.makedirs(os.path.join(now_dir, "assets/weights"), exist_ok=True)
46
+ os.environ["TEMP"] = tmp
47
+ warnings.filterwarnings("ignore")
48
+ torch.manual_seed(114514)
49
+
50
+
51
+ load_dotenv()
52
+ config = Config()
53
+ vc = VC(config)
54
+
55
+ if config.dml == True:
56
+
57
+ def forward_dml(ctx, x, scale):
58
+ ctx.scale = scale
59
+ res = x.clone().detach()
60
+ return res
61
+
62
+ fairseq.modules.grad_multiply.GradMultiply.forward = forward_dml
63
+ i18n = I18nAuto()
64
+ logger.info(i18n)
65
+ # 判断是否有能用来训练和加速推理的N卡
66
+ ngpu = torch.cuda.device_count()
67
+ gpu_infos = []
68
+ mem = []
69
+ if_gpu_ok = False
70
+
71
+ if torch.cuda.is_available() or ngpu != 0:
72
+ for i in range(ngpu):
73
+ gpu_name = torch.cuda.get_device_name(i)
74
+ if any(
75
+ value in gpu_name.upper()
76
+ for value in [
77
+ "10",
78
+ "16",
79
+ "20",
80
+ "30",
81
+ "40",
82
+ "A2",
83
+ "A3",
84
+ "A4",
85
+ "P4",
86
+ "A50",
87
+ "500",
88
+ "A60",
89
+ "70",
90
+ "80",
91
+ "90",
92
+ "M4",
93
+ "T4",
94
+ "TITAN",
95
+ ]
96
+ ):
97
+ # A10#A100#V100#A40#P40#M40#K80#A4500
98
+ if_gpu_ok = True # 至少有一张能用的N卡
99
+ gpu_infos.append("%s\t%s" % (i, gpu_name))
100
+ mem.append(
101
+ int(
102
+ torch.cuda.get_device_properties(i).total_memory
103
+ / 1024
104
+ / 1024
105
+ / 1024
106
+ + 0.4
107
+ )
108
+ )
109
+ if if_gpu_ok and len(gpu_infos) > 0:
110
+ gpu_info = "\n".join(gpu_infos)
111
+ default_batch_size = min(mem) // 2
112
+ else:
113
+ gpu_info = i18n("很遗憾您这没有能用的显卡来支持您训练")
114
+ default_batch_size = 1
115
+ gpus = "-".join([i[0] for i in gpu_infos])
116
+
117
+
118
+ class ToolButton(gr.Button, gr.components.FormComponent):
119
+ """Small button with single emoji as text, fits inside gradio forms"""
120
+
121
+ def __init__(self, **kwargs):
122
+ super().__init__(variant="tool", **kwargs)
123
+
124
+ def get_block_name(self):
125
+ return "button"
126
+
127
+
128
+ weight_root = os.getenv("weight_root")
129
+ weight_uvr5_root = os.getenv("weight_uvr5_root")
130
+ index_root = os.getenv("index_root")
131
+
132
+ names = []
133
+ for name in os.listdir(weight_root):
134
+ if name.endswith(".pth"):
135
+ names.append(name)
136
+ index_paths = []
137
+ for root, dirs, files in os.walk(index_root, topdown=False):
138
+ for name in files:
139
+ if name.endswith(".index") and "trained" not in name:
140
+ index_paths.append("%s/%s" % (root, name))
141
+ uvr5_names = []
142
+ for name in os.listdir(weight_uvr5_root):
143
+ if name.endswith(".pth") or "onnx" in name:
144
+ uvr5_names.append(name.replace(".pth", ""))
145
+
146
+
147
+ def change_choices():
148
+ names = []
149
+ for name in os.listdir(weight_root):
150
+ if name.endswith(".pth"):
151
+ names.append(name)
152
+ index_paths = []
153
+ for root, dirs, files in os.walk(index_root, topdown=False):
154
+ for name in files:
155
+ if name.endswith(".index") and "trained" not in name:
156
+ index_paths.append("%s/%s" % (root, name))
157
+ audio_files=[]
158
+ for filename in os.listdir("./audios"):
159
+ if filename.endswith(('.wav','.mp3','.ogg')):
160
+ audio_files.append('./audios/'+filename)
161
+ return {"choices": sorted(names), "__type__": "update"}, {
162
+ "choices": sorted(index_paths),
163
+ "__type__": "update",
164
+ }, {"choices": sorted(audio_files), "__type__": "update"}
165
+
166
+ def clean():
167
+ return {"value": "", "__type__": "update"}
168
+
169
+
170
+ def export_onnx():
171
+ from infer.modules.onnx.export import export_onnx as eo
172
+
173
+ eo()
174
+
175
+
176
+ sr_dict = {
177
+ "32k": 32000,
178
+ "40k": 40000,
179
+ "48k": 48000,
180
+ }
181
+
182
+
183
+ def if_done(done, p):
184
+ while 1:
185
+ if p.poll() is None:
186
+ sleep(0.5)
187
+ else:
188
+ break
189
+ done[0] = True
190
+
191
+
192
+ def if_done_multi(done, ps):
193
+ while 1:
194
+ # poll==None代表进程未结束
195
+ # 只要有一个进程未结束都不停
196
+ flag = 1
197
+ for p in ps:
198
+ if p.poll() is None:
199
+ flag = 0
200
+ sleep(0.5)
201
+ break
202
+ if flag == 1:
203
+ break
204
+ done[0] = True
205
+
206
+
207
+ def preprocess_dataset(trainset_dir, exp_dir, sr, n_p):
208
+ sr = sr_dict[sr]
209
+ os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
210
+ f = open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "w")
211
+ f.close()
212
+ per = 3.0 if config.is_half else 3.7
213
+ cmd = '"%s" infer/modules/train/preprocess.py "%s" %s %s "%s/logs/%s" %s %.1f' % (
214
+ config.python_cmd,
215
+ trainset_dir,
216
+ sr,
217
+ n_p,
218
+ now_dir,
219
+ exp_dir,
220
+ config.noparallel,
221
+ per,
222
+ )
223
+ logger.info(cmd)
224
+ p = Popen(cmd, shell=True) # , stdin=PIPE, stdout=PIPE,stderr=PIPE,cwd=now_dir
225
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
226
+ done = [False]
227
+ threading.Thread(
228
+ target=if_done,
229
+ args=(
230
+ done,
231
+ p,
232
+ ),
233
+ ).start()
234
+ while 1:
235
+ with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
236
+ yield (f.read())
237
+ sleep(1)
238
+ if done[0]:
239
+ break
240
+ with open("%s/logs/%s/preprocess.log" % (now_dir, exp_dir), "r") as f:
241
+ log = f.read()
242
+ logger.info(log)
243
+ yield log
244
+
245
+
246
+ # but2.click(extract_f0,[gpus6,np7,f0method8,if_f0_3,trainset_dir4],[info2])
247
+ def extract_f0_feature(gpus, n_p, f0method, if_f0, exp_dir, version19, gpus_rmvpe):
248
+ gpus = gpus.split("-")
249
+ os.makedirs("%s/logs/%s" % (now_dir, exp_dir), exist_ok=True)
250
+ f = open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "w")
251
+ f.close()
252
+ if if_f0:
253
+ if f0method != "rmvpe_gpu":
254
+ cmd = (
255
+ '"%s" infer/modules/train/extract/extract_f0_print.py "%s/logs/%s" %s %s'
256
+ % (
257
+ config.python_cmd,
258
+ now_dir,
259
+ exp_dir,
260
+ n_p,
261
+ f0method,
262
+ )
263
+ )
264
+ logger.info(cmd)
265
+ p = Popen(
266
+ cmd, shell=True, cwd=now_dir
267
+ ) # , stdin=PIPE, stdout=PIPE,stderr=PIPE
268
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
269
+ done = [False]
270
+ threading.Thread(
271
+ target=if_done,
272
+ args=(
273
+ done,
274
+ p,
275
+ ),
276
+ ).start()
277
+ else:
278
+ if gpus_rmvpe != "-":
279
+ gpus_rmvpe = gpus_rmvpe.split("-")
280
+ leng = len(gpus_rmvpe)
281
+ ps = []
282
+ for idx, n_g in enumerate(gpus_rmvpe):
283
+ cmd = (
284
+ '"%s" infer/modules/train/extract/extract_f0_rmvpe.py %s %s %s "%s/logs/%s" %s '
285
+ % (
286
+ config.python_cmd,
287
+ leng,
288
+ idx,
289
+ n_g,
290
+ now_dir,
291
+ exp_dir,
292
+ config.is_half,
293
+ )
294
+ )
295
+ logger.info(cmd)
296
+ p = Popen(
297
+ cmd, shell=True, cwd=now_dir
298
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
299
+ ps.append(p)
300
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
301
+ done = [False]
302
+ threading.Thread(
303
+ target=if_done_multi, #
304
+ args=(
305
+ done,
306
+ ps,
307
+ ),
308
+ ).start()
309
+ else:
310
+ cmd = (
311
+ config.python_cmd
312
+ + ' infer/modules/train/extract/extract_f0_rmvpe_dml.py "%s/logs/%s" '
313
+ % (
314
+ now_dir,
315
+ exp_dir,
316
+ )
317
+ )
318
+ logger.info(cmd)
319
+ p = Popen(
320
+ cmd, shell=True, cwd=now_dir
321
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
322
+ p.wait()
323
+ done = [True]
324
+ while 1:
325
+ with open(
326
+ "%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r"
327
+ ) as f:
328
+ yield (f.read())
329
+ sleep(1)
330
+ if done[0]:
331
+ break
332
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
333
+ log = f.read()
334
+ logger.info(log)
335
+ yield log
336
+ ####对不同part分别开多进程
337
+ """
338
+ n_part=int(sys.argv[1])
339
+ i_part=int(sys.argv[2])
340
+ i_gpu=sys.argv[3]
341
+ exp_dir=sys.argv[4]
342
+ os.environ["CUDA_VISIBLE_DEVICES"]=str(i_gpu)
343
+ """
344
+ leng = len(gpus)
345
+ ps = []
346
+ for idx, n_g in enumerate(gpus):
347
+ cmd = (
348
+ '"%s" infer/modules/train/extract_feature_print.py %s %s %s %s "%s/logs/%s" %s'
349
+ % (
350
+ config.python_cmd,
351
+ config.device,
352
+ leng,
353
+ idx,
354
+ n_g,
355
+ now_dir,
356
+ exp_dir,
357
+ version19,
358
+ )
359
+ )
360
+ logger.info(cmd)
361
+ p = Popen(
362
+ cmd, shell=True, cwd=now_dir
363
+ ) # , shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=now_dir
364
+ ps.append(p)
365
+ ###煞笔gr, popen read都非得全跑完了再一次性读取, 不用gr就正常读一句输出一句;只能额外弄出一个文本流定时读
366
+ done = [False]
367
+ threading.Thread(
368
+ target=if_done_multi,
369
+ args=(
370
+ done,
371
+ ps,
372
+ ),
373
+ ).start()
374
+ while 1:
375
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
376
+ yield (f.read())
377
+ sleep(1)
378
+ if done[0]:
379
+ break
380
+ with open("%s/logs/%s/extract_f0_feature.log" % (now_dir, exp_dir), "r") as f:
381
+ log = f.read()
382
+ logger.info(log)
383
+ yield log
384
+
385
+
386
+ def get_pretrained_models(path_str, f0_str, sr2):
387
+ if_pretrained_generator_exist = os.access(
388
+ "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2), os.F_OK
389
+ )
390
+ if_pretrained_discriminator_exist = os.access(
391
+ "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2), os.F_OK
392
+ )
393
+ if not if_pretrained_generator_exist:
394
+ logger.warn(
395
+ "assets/pretrained%s/%sG%s.pth not exist, will not use pretrained model",
396
+ path_str,
397
+ f0_str,
398
+ sr2,
399
+ )
400
+ if not if_pretrained_discriminator_exist:
401
+ logger.warn(
402
+ "assets/pretrained%s/%sD%s.pth not exist, will not use pretrained model",
403
+ path_str,
404
+ f0_str,
405
+ sr2,
406
+ )
407
+ return (
408
+ "assets/pretrained%s/%sG%s.pth" % (path_str, f0_str, sr2)
409
+ if if_pretrained_generator_exist
410
+ else "",
411
+ "assets/pretrained%s/%sD%s.pth" % (path_str, f0_str, sr2)
412
+ if if_pretrained_discriminator_exist
413
+ else "",
414
+ )
415
+
416
+
417
+ def change_sr2(sr2, if_f0_3, version19):
418
+ path_str = "" if version19 == "v1" else "_v2"
419
+ f0_str = "f0" if if_f0_3 else ""
420
+ return get_pretrained_models(path_str, f0_str, sr2)
421
+
422
+
423
+ def change_version19(sr2, if_f0_3, version19):
424
+ path_str = "" if version19 == "v1" else "_v2"
425
+ if sr2 == "32k" and version19 == "v1":
426
+ sr2 = "40k"
427
+ to_return_sr2 = (
428
+ {"choices": ["40k", "48k"], "__type__": "update", "value": sr2}
429
+ if version19 == "v1"
430
+ else {"choices": ["40k", "48k", "32k"], "__type__": "update", "value": sr2}
431
+ )
432
+ f0_str = "f0" if if_f0_3 else ""
433
+ return (
434
+ *get_pretrained_models(path_str, f0_str, sr2),
435
+ to_return_sr2,
436
+ )
437
+
438
+
439
+ def change_f0(if_f0_3, sr2, version19): # f0method8,pretrained_G14,pretrained_D15
440
+ path_str = "" if version19 == "v1" else "_v2"
441
+ return (
442
+ {"visible": if_f0_3, "__type__": "update"},
443
+ *get_pretrained_models(path_str, "f0", sr2),
444
+ )
445
+
446
+
447
+ # but3.click(click_train,[exp_dir1,sr2,if_f0_3,save_epoch10,total_epoch11,batch_size12,if_save_latest13,pretrained_G14,pretrained_D15,gpus16])
448
+ def click_train(
449
+ exp_dir1,
450
+ sr2,
451
+ if_f0_3,
452
+ spk_id5,
453
+ save_epoch10,
454
+ total_epoch11,
455
+ batch_size12,
456
+ if_save_latest13,
457
+ pretrained_G14,
458
+ pretrained_D15,
459
+ gpus16,
460
+ if_cache_gpu17,
461
+ if_save_every_weights18,
462
+ version19,
463
+ ):
464
+ # 生成filelist
465
+ exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
466
+ os.makedirs(exp_dir, exist_ok=True)
467
+ gt_wavs_dir = "%s/0_gt_wavs" % (exp_dir)
468
+ feature_dir = (
469
+ "%s/3_feature256" % (exp_dir)
470
+ if version19 == "v1"
471
+ else "%s/3_feature768" % (exp_dir)
472
+ )
473
+ if if_f0_3:
474
+ f0_dir = "%s/2a_f0" % (exp_dir)
475
+ f0nsf_dir = "%s/2b-f0nsf" % (exp_dir)
476
+ names = (
477
+ set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)])
478
+ & set([name.split(".")[0] for name in os.listdir(feature_dir)])
479
+ & set([name.split(".")[0] for name in os.listdir(f0_dir)])
480
+ & set([name.split(".")[0] for name in os.listdir(f0nsf_dir)])
481
+ )
482
+ else:
483
+ names = set([name.split(".")[0] for name in os.listdir(gt_wavs_dir)]) & set(
484
+ [name.split(".")[0] for name in os.listdir(feature_dir)]
485
+ )
486
+ opt = []
487
+ for name in names:
488
+ if if_f0_3:
489
+ opt.append(
490
+ "%s/%s.wav|%s/%s.npy|%s/%s.wav.npy|%s/%s.wav.npy|%s"
491
+ % (
492
+ gt_wavs_dir.replace("\\", "\\\\"),
493
+ name,
494
+ feature_dir.replace("\\", "\\\\"),
495
+ name,
496
+ f0_dir.replace("\\", "\\\\"),
497
+ name,
498
+ f0nsf_dir.replace("\\", "\\\\"),
499
+ name,
500
+ spk_id5,
501
+ )
502
+ )
503
+ else:
504
+ opt.append(
505
+ "%s/%s.wav|%s/%s.npy|%s"
506
+ % (
507
+ gt_wavs_dir.replace("\\", "\\\\"),
508
+ name,
509
+ feature_dir.replace("\\", "\\\\"),
510
+ name,
511
+ spk_id5,
512
+ )
513
+ )
514
+ fea_dim = 256 if version19 == "v1" else 768
515
+ if if_f0_3:
516
+ for _ in range(2):
517
+ opt.append(
518
+ "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s/logs/mute/2a_f0/mute.wav.npy|%s/logs/mute/2b-f0nsf/mute.wav.npy|%s"
519
+ % (now_dir, sr2, now_dir, fea_dim, now_dir, now_dir, spk_id5)
520
+ )
521
+ else:
522
+ for _ in range(2):
523
+ opt.append(
524
+ "%s/logs/mute/0_gt_wavs/mute%s.wav|%s/logs/mute/3_feature%s/mute.npy|%s"
525
+ % (now_dir, sr2, now_dir, fea_dim, spk_id5)
526
+ )
527
+ shuffle(opt)
528
+ with open("%s/filelist.txt" % exp_dir, "w") as f:
529
+ f.write("\n".join(opt))
530
+ logger.debug("Write filelist done")
531
+ # 生成config#无需生成config
532
+ # cmd = python_cmd + " train_nsf_sim_cache_sid_load_pretrain.py -e mi-test -sr 40k -f0 1 -bs 4 -g 0 -te 10 -se 5 -pg pretrained/f0G40k.pth -pd pretrained/f0D40k.pth -l 1 -c 0"
533
+ logger.info("Use gpus: %s", str(gpus16))
534
+ if pretrained_G14 == "":
535
+ logger.info("No pretrained Generator")
536
+ if pretrained_D15 == "":
537
+ logger.info("No pretrained Discriminator")
538
+ if version19 == "v1" or sr2 == "40k":
539
+ config_path = "v1/%s.json" % sr2
540
+ else:
541
+ config_path = "v2/%s.json" % sr2
542
+ config_save_path = os.path.join(exp_dir, "config.json")
543
+ if not pathlib.Path(config_save_path).exists():
544
+ with open(config_save_path, "w", encoding="utf-8") as f:
545
+ json.dump(
546
+ config.json_config[config_path],
547
+ f,
548
+ ensure_ascii=False,
549
+ indent=4,
550
+ sort_keys=True,
551
+ )
552
+ f.write("\n")
553
+ if gpus16:
554
+ cmd = (
555
+ '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -g %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
556
+ % (
557
+ config.python_cmd,
558
+ exp_dir1,
559
+ sr2,
560
+ 1 if if_f0_3 else 0,
561
+ batch_size12,
562
+ gpus16,
563
+ total_epoch11,
564
+ save_epoch10,
565
+ "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
566
+ "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
567
+ 1 if if_save_latest13 == i18n("是") else 0,
568
+ 1 if if_cache_gpu17 == i18n("是") else 0,
569
+ 1 if if_save_every_weights18 == i18n("是") else 0,
570
+ version19,
571
+ )
572
+ )
573
+ else:
574
+ cmd = (
575
+ '"%s" infer/modules/train/train.py -e "%s" -sr %s -f0 %s -bs %s -te %s -se %s %s %s -l %s -c %s -sw %s -v %s'
576
+ % (
577
+ config.python_cmd,
578
+ exp_dir1,
579
+ sr2,
580
+ 1 if if_f0_3 else 0,
581
+ batch_size12,
582
+ total_epoch11,
583
+ save_epoch10,
584
+ "-pg %s" % pretrained_G14 if pretrained_G14 != "" else "",
585
+ "-pd %s" % pretrained_D15 if pretrained_D15 != "" else "",
586
+ 1 if if_save_latest13 == i18n("是") else 0,
587
+ 1 if if_cache_gpu17 == i18n("是") else 0,
588
+ 1 if if_save_every_weights18 == i18n("是") else 0,
589
+ version19,
590
+ )
591
+ )
592
+ logger.info(cmd)
593
+ p = Popen(cmd, shell=True, cwd=now_dir)
594
+ p.wait()
595
+ return "训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"
596
+
597
+
598
+ # but4.click(train_index, [exp_dir1], info3)
599
+ def train_index(exp_dir1, version19):
600
+ # exp_dir = "%s/logs/%s" % (now_dir, exp_dir1)
601
+ exp_dir = "logs/%s" % (exp_dir1)
602
+ os.makedirs(exp_dir, exist_ok=True)
603
+ feature_dir = (
604
+ "%s/3_feature256" % (exp_dir)
605
+ if version19 == "v1"
606
+ else "%s/3_feature768" % (exp_dir)
607
+ )
608
+ if not os.path.exists(feature_dir):
609
+ return "请先进行特征提取!"
610
+ listdir_res = list(os.listdir(feature_dir))
611
+ if len(listdir_res) == 0:
612
+ return "请先进行特征提取!"
613
+ infos = []
614
+ npys = []
615
+ for name in sorted(listdir_res):
616
+ phone = np.load("%s/%s" % (feature_dir, name))
617
+ npys.append(phone)
618
+ big_npy = np.concatenate(npys, 0)
619
+ big_npy_idx = np.arange(big_npy.shape[0])
620
+ np.random.shuffle(big_npy_idx)
621
+ big_npy = big_npy[big_npy_idx]
622
+ if big_npy.shape[0] > 2e5:
623
+ infos.append("Trying doing kmeans %s shape to 10k centers." % big_npy.shape[0])
624
+ yield "\n".join(infos)
625
+ try:
626
+ big_npy = (
627
+ MiniBatchKMeans(
628
+ n_clusters=10000,
629
+ verbose=True,
630
+ batch_size=256 * config.n_cpu,
631
+ compute_labels=False,
632
+ init="random",
633
+ )
634
+ .fit(big_npy)
635
+ .cluster_centers_
636
+ )
637
+ except:
638
+ info = traceback.format_exc()
639
+ logger.info(info)
640
+ infos.append(info)
641
+ yield "\n".join(infos)
642
+
643
+ np.save("%s/total_fea.npy" % exp_dir, big_npy)
644
+ n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
645
+ infos.append("%s,%s" % (big_npy.shape, n_ivf))
646
+ yield "\n".join(infos)
647
+ index = faiss.index_factory(256 if version19 == "v1" else 768, "IVF%s,Flat" % n_ivf)
648
+ # index = faiss.index_factory(256if version19=="v1"else 768, "IVF%s,PQ128x4fs,RFlat"%n_ivf)
649
+ infos.append("training")
650
+ yield "\n".join(infos)
651
+ index_ivf = faiss.extract_index_ivf(index) #
652
+ index_ivf.nprobe = 1
653
+ index.train(big_npy)
654
+ faiss.write_index(
655
+ index,
656
+ "%s/trained_IVF%s_Flat_nprobe_%s_%s_%s.index"
657
+ % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
658
+ )
659
+
660
+ infos.append("adding")
661
+ yield "\n".join(infos)
662
+ batch_size_add = 8192
663
+ for i in range(0, big_npy.shape[0], batch_size_add):
664
+ index.add(big_npy[i : i + batch_size_add])
665
+ faiss.write_index(
666
+ index,
667
+ "%s/added_IVF%s_Flat_nprobe_%s_%s_%s.index"
668
+ % (exp_dir, n_ivf, index_ivf.nprobe, exp_dir1, version19),
669
+ )
670
+ infos.append(
671
+ "成功构建索引,added_IVF%s_Flat_nprobe_%s_%s_%s.index"
672
+ % (n_ivf, index_ivf.nprobe, exp_dir1, version19)
673
+ )
674
+ # faiss.write_index(index, '%s/added_IVF%s_Flat_FastScan_%s.index'%(exp_dir,n_ivf,version19))
675
+ # infos.append("成功构建索引,added_IVF%s_Flat_FastScan_%s.index"%(n_ivf,version19))
676
+ yield "\n".join(infos)
677
+
678
+
679
+ # but5.click(train1key, [exp_dir1, sr2, if_f0_3, trainset_dir4, spk_id5, gpus6, np7, f0method8, save_epoch10, total_epoch11, batch_size12, if_save_latest13, pretrained_G14, pretrained_D15, gpus16, if_cache_gpu17], info3)
680
+ def train1key(
681
+ exp_dir1,
682
+ sr2,
683
+ if_f0_3,
684
+ trainset_dir4,
685
+ spk_id5,
686
+ np7,
687
+ f0method8,
688
+ save_epoch10,
689
+ total_epoch11,
690
+ batch_size12,
691
+ if_save_latest13,
692
+ pretrained_G14,
693
+ pretrained_D15,
694
+ gpus16,
695
+ if_cache_gpu17,
696
+ if_save_every_weights18,
697
+ version19,
698
+ gpus_rmvpe,
699
+ ):
700
+ infos = []
701
+
702
+ def get_info_str(strr):
703
+ infos.append(strr)
704
+ return "\n".join(infos)
705
+
706
+ ####### step1:处理数据
707
+ yield get_info_str(i18n("step1:正在处理数据"))
708
+ [get_info_str(_) for _ in preprocess_dataset(trainset_dir4, exp_dir1, sr2, np7)]
709
+
710
+ ####### step2a:提取音高
711
+ yield get_info_str(i18n("step2:正在提取音高&正在提取特征"))
712
+ [
713
+ get_info_str(_)
714
+ for _ in extract_f0_feature(
715
+ gpus16, np7, f0method8, if_f0_3, exp_dir1, version19, gpus_rmvpe
716
+ )
717
+ ]
718
+
719
+ ####### step3a:训练模型
720
+ yield get_info_str(i18n("step3a:正在训练模型"))
721
+ click_train(
722
+ exp_dir1,
723
+ sr2,
724
+ if_f0_3,
725
+ spk_id5,
726
+ save_epoch10,
727
+ total_epoch11,
728
+ batch_size12,
729
+ if_save_latest13,
730
+ pretrained_G14,
731
+ pretrained_D15,
732
+ gpus16,
733
+ if_cache_gpu17,
734
+ if_save_every_weights18,
735
+ version19,
736
+ )
737
+ yield get_info_str(i18n("训练结束, 您可查看控制台训练日志或实验文件夹下的train.log"))
738
+
739
+ ####### step3b:训练索引
740
+ [get_info_str(_) for _ in train_index(exp_dir1, version19)]
741
+ yield get_info_str(i18n("全流程结束!"))
742
+
743
+
744
+ # ckpt_path2.change(change_info_,[ckpt_path2],[sr__,if_f0__])
745
+ def change_info_(ckpt_path):
746
+ if not os.path.exists(ckpt_path.replace(os.path.basename(ckpt_path), "train.log")):
747
+ return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
748
+ try:
749
+ with open(
750
+ ckpt_path.replace(os.path.basename(ckpt_path), "train.log"), "r"
751
+ ) as f:
752
+ info = eval(f.read().strip("\n").split("\n")[0].split("\t")[-1])
753
+ sr, f0 = info["sample_rate"], info["if_f0"]
754
+ version = "v2" if ("version" in info and info["version"] == "v2") else "v1"
755
+ return sr, str(f0), version
756
+ except:
757
+ traceback.print_exc()
758
+ return {"__type__": "update"}, {"__type__": "update"}, {"__type__": "update"}
759
+
760
+
761
+ F0GPUVisible = config.dml == False
762
+
763
+
764
+ def change_f0_method(f0method8):
765
+ if f0method8 == "rmvpe_gpu":
766
+ visible = F0GPUVisible
767
+ else:
768
+ visible = False
769
+ return {"visible": visible, "__type__": "update"}
770
+
771
+ def find_model():
772
+ if len(names) > 0:
773
+ vc.get_vc(sorted(names)[0],None,None)
774
+ return sorted(names)[0]
775
+ else:
776
+ try:
777
+ gr.Info("Do not forget to choose a model.")
778
+ except:
779
+ pass
780
+ return ''
781
+
782
+ def find_audios(index=False):
783
+ audio_files=[]
784
+ if not os.path.exists('./audios'): os.mkdir("./audios")
785
+ for filename in os.listdir("./audios"):
786
+ if filename.endswith(('.wav','.mp3','.ogg')):
787
+ audio_files.append("./audios/"+filename)
788
+ if index:
789
+ if len(audio_files) > 0: return sorted(audio_files)[0]
790
+ else: return ""
791
+ elif len(audio_files) > 0: return sorted(audio_files)
792
+ else: return []
793
+
794
+ def get_index():
795
+ if find_model() != '':
796
+ chosen_model=sorted(names)[0].split(".")[0]
797
+ logs_path="./logs/"+chosen_model
798
+ if os.path.exists(logs_path):
799
+ for file in os.listdir(logs_path):
800
+ if file.endswith(".index"):
801
+ return os.path.join(logs_path, file)
802
+ return ''
803
+ else:
804
+ return ''
805
+
806
+ def get_indexes():
807
+ indexes_list=[]
808
+ for dirpath, dirnames, filenames in os.walk("./logs/"):
809
+ for filename in filenames:
810
+ if filename.endswith(".index"):
811
+ indexes_list.append(os.path.join(dirpath,filename))
812
+ if len(indexes_list) > 0:
813
+ return indexes_list
814
+ else:
815
+ return ''
816
+
817
+ def save_wav(file):
818
+ try:
819
+ file_path=file.name
820
+ shutil.move(file_path,'./audios')
821
+ return './audios/'+os.path.basename(file_path)
822
+ except AttributeError:
823
+ try:
824
+ new_name = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")+'.wav'
825
+ new_path='./audios/'+new_name
826
+ shutil.move(file,new_path)
827
+ return new_path
828
+ except TypeError:
829
+ return None
830
+
831
+ def download_from_url(url, model):
832
+ if url == '':
833
+ return "URL cannot be left empty."
834
+ if model =='':
835
+ return "You need to name your model. For example: My-Model"
836
+ url = url.strip()
837
+ zip_dirs = ["zips", "unzips"]
838
+ for directory in zip_dirs:
839
+ if os.path.exists(directory):
840
+ shutil.rmtree(directory)
841
+ os.makedirs("zips", exist_ok=True)
842
+ os.makedirs("unzips", exist_ok=True)
843
+ zipfile = model + '.zip'
844
+ zipfile_path = './zips/' + zipfile
845
+ try:
846
+ if "drive.google.com" in url:
847
+ subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
848
+ elif "mega.nz" in url:
849
+ m = Mega()
850
+ m.download_url(url, './zips')
851
+ else:
852
+ subprocess.run(["wget", url, "-O", zipfile_path])
853
+ for filename in os.listdir("./zips"):
854
+ if filename.endswith(".zip"):
855
+ zipfile_path = os.path.join("./zips/",filename)
856
+ shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
857
+ else:
858
+ return "No zipfile found."
859
+ for root, dirs, files in os.walk('./unzips'):
860
+ for file in files:
861
+ file_path = os.path.join(root, file)
862
+ if file.endswith(".index"):
863
+ os.mkdir(f'./logs/{model}')
864
+ shutil.copy2(file_path,f'./logs/{model}')
865
+ elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
866
+ shutil.copy(file_path,f'./assets/weights/{model}.pth')
867
+ shutil.rmtree("zips")
868
+ shutil.rmtree("unzips")
869
+ return "Success."
870
+ except:
871
+ return "There's been an error."
872
+
873
+ def upload_to_dataset(files, dir):
874
+ if dir == '':
875
+ dir = './dataset/'+datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
876
+ if not os.path.exists(dir):
877
+ os.makedirs(dir)
878
+ for file in files:
879
+ path=file.name
880
+ shutil.copy2(path,dir)
881
+ try:
882
+ gr.Info(i18n("处理数据"))
883
+ except:
884
+ pass
885
+ return i18n("处理数据"), {"value":dir,"__type__":"update"}
886
+
887
+ def download_model_files(model):
888
+ model_found = False
889
+ index_found = False
890
+ if os.path.exists(f'./assets/weights/{model}.pth'): model_found = True
891
+ if os.path.exists(f'./logs/{model}'):
892
+ for file in os.listdir(f'./logs/{model}'):
893
+ if file.endswith('.index') and 'added' in file:
894
+ log_file = file
895
+ index_found = True
896
+ if model_found and index_found:
897
+ return [f'./assets/weights/{model}.pth', f'./logs/{model}/{log_file}'], "Done"
898
+ elif model_found and not index_found:
899
+ return f'./assets/weights/{model}.pth', "Could not find Index file."
900
+ elif index_found and not model_found:
901
+ return f'./logs/{model}/{log_file}', f'Make sure the Voice Name is correct. I could not find {model}.pth'
902
+ else:
903
+ return None, f'Could not find {model}.pth or corresponding Index file.'
904
+
905
+ with gr.Blocks(title="🔊",theme=gr.themes.Base(primary_hue="rose",neutral_hue="zinc")) as app:
906
+ with gr.Row():
907
+ gr.HTML("<img src='file/a.png' alt='image'>")
908
+ with gr.Tabs():
909
+ with gr.TabItem(i18n("模型推理")):
910
+ with gr.Row():
911
+ sid0 = gr.Dropdown(label=i18n("推理音色"), choices=sorted(names), value=find_model())
912
+ refresh_button = gr.Button(i18n("刷新音色列表和索引路径"), variant="primary")
913
+ #clean_button = gr.Button(i18n("卸载音色省显存"), variant="primary")
914
+ spk_item = gr.Slider(
915
+ minimum=0,
916
+ maximum=2333,
917
+ step=1,
918
+ label=i18n("请选择说话人id"),
919
+ value=0,
920
+ visible=False,
921
+ interactive=True,
922
+ )
923
+ #clean_button.click(
924
+ # fn=clean, inputs=[], outputs=[sid0], api_name="infer_clean"
925
+ #)
926
+ vc_transform0 = gr.Number(
927
+ label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
928
+ )
929
+ but0 = gr.Button(i18n("转换"), variant="primary")
930
+ with gr.Row():
931
+ with gr.Column():
932
+ with gr.Row():
933
+ dropbox = gr.File(label="Drop your audio here & hit the Reload button.")
934
+ with gr.Row():
935
+ record_button=gr.Audio(source="microphone", label="OR Record audio.", type="filepath")
936
+ with gr.Row():
937
+ input_audio0 = gr.Dropdown(
938
+ label=i18n("输入待处理音频文件路径(默认是正确格式示例)"),
939
+ value=find_audios(True),
940
+ choices=find_audios()
941
+ )
942
+ record_button.change(fn=save_wav, inputs=[record_button], outputs=[input_audio0])
943
+ dropbox.upload(fn=save_wav, inputs=[dropbox], outputs=[input_audio0])
944
+ with gr.Column():
945
+ with gr.Accordion(label=i18n("自动检测index路径,下拉式选择(dropdown)"), open=False):
946
+ file_index2 = gr.Dropdown(
947
+ label=i18n("自动检测index路径,下拉式选择(dropdown)"),
948
+ choices=get_indexes(),
949
+ interactive=True,
950
+ value=get_index()
951
+ )
952
+ index_rate1 = gr.Slider(
953
+ minimum=0,
954
+ maximum=1,
955
+ label=i18n("检索特征占比"),
956
+ value=0.66,
957
+ interactive=True,
958
+ )
959
+ vc_output2 = gr.Audio(label=i18n("输出音频(右下角三个点,点了可以下载)"))
960
+ with gr.Accordion(label=i18n("常规设置"), open=False):
961
+ f0method0 = gr.Radio(
962
+ label=i18n(
963
+ "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
964
+ ),
965
+ choices=["pm", "harvest", "crepe", "rmvpe"]
966
+ if config.dml == False
967
+ else ["pm", "harvest", "rmvpe"],
968
+ value="rmvpe",
969
+ interactive=True,
970
+ )
971
+ filter_radius0 = gr.Slider(
972
+ minimum=0,
973
+ maximum=7,
974
+ label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
975
+ value=3,
976
+ step=1,
977
+ interactive=True,
978
+ )
979
+ resample_sr0 = gr.Slider(
980
+ minimum=0,
981
+ maximum=48000,
982
+ label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
983
+ value=0,
984
+ step=1,
985
+ interactive=True,
986
+ visible=False
987
+ )
988
+ rms_mix_rate0 = gr.Slider(
989
+ minimum=0,
990
+ maximum=1,
991
+ label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
992
+ value=0.21,
993
+ interactive=True,
994
+ )
995
+ protect0 = gr.Slider(
996
+ minimum=0,
997
+ maximum=0.5,
998
+ label=i18n(
999
+ "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能���低索引效果"
1000
+ ),
1001
+ value=0.33,
1002
+ step=0.01,
1003
+ interactive=True,
1004
+ )
1005
+ file_index1 = gr.Textbox(
1006
+ label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
1007
+ value="",
1008
+ interactive=True,
1009
+ visible=False
1010
+ )
1011
+ refresh_button.click(
1012
+ fn=change_choices,
1013
+ inputs=[],
1014
+ outputs=[sid0, file_index2, input_audio0],
1015
+ api_name="infer_refresh",
1016
+ )
1017
+ # file_big_npy1 = gr.Textbox(
1018
+ # label=i18n("特征文件路径"),
1019
+ # value="E:\\codes\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1020
+ # interactive=True,
1021
+ # )
1022
+ with gr.Row():
1023
+ f0_file = gr.File(label=i18n("F0曲线文件, 可选, 一行一个音高, 代替默认F0及升降调"), visible=False)
1024
+ with gr.Row():
1025
+ vc_output1 = gr.Textbox(label=i18n("输出信息"))
1026
+ but0.click(
1027
+ vc.vc_single,
1028
+ [
1029
+ spk_item,
1030
+ input_audio0,
1031
+ vc_transform0,
1032
+ f0_file,
1033
+ f0method0,
1034
+ file_index1,
1035
+ file_index2,
1036
+ # file_big_npy1,
1037
+ index_rate1,
1038
+ filter_radius0,
1039
+ resample_sr0,
1040
+ rms_mix_rate0,
1041
+ protect0,
1042
+ ],
1043
+ [vc_output1, vc_output2],
1044
+ api_name="infer_convert",
1045
+ )
1046
+ with gr.Row():
1047
+ with gr.Accordion(open=False, label=i18n("批量转换, 输入待转换音频文件夹, 或上传多个音频文件, 在指定文件夹(默认opt)下输出转换的音频. ")):
1048
+ with gr.Row():
1049
+ opt_input = gr.Textbox(label=i18n("指定输出文件夹"), value="opt")
1050
+ vc_transform1 = gr.Number(
1051
+ label=i18n("变调(整数, 半音数量, 升八度12降八度-12)"), value=0
1052
+ )
1053
+ f0method1 = gr.Radio(
1054
+ label=i18n(
1055
+ "选择音高提取算法,输入歌声可用pm提速,harvest低音好但巨慢无比,crepe效果好但吃GPU,rmvpe效果最好且微吃GPU"
1056
+ ),
1057
+ choices=["pm", "harvest", "crepe", "rmvpe"]
1058
+ if config.dml == False
1059
+ else ["pm", "harvest", "rmvpe"],
1060
+ value="pm",
1061
+ interactive=True,
1062
+ )
1063
+ with gr.Row():
1064
+ filter_radius1 = gr.Slider(
1065
+ minimum=0,
1066
+ maximum=7,
1067
+ label=i18n(">=3则使用对harvest音高识别的结果使用中值滤波,数值为滤波半径,使用可以削弱哑音"),
1068
+ value=3,
1069
+ step=1,
1070
+ interactive=True,
1071
+ visible=False
1072
+ )
1073
+ with gr.Row():
1074
+ file_index3 = gr.Textbox(
1075
+ label=i18n("特征检索库文件路径,为空则使用下拉的选择结果"),
1076
+ value="",
1077
+ interactive=True,
1078
+ visible=False
1079
+ )
1080
+ file_index4 = gr.Dropdown(
1081
+ label=i18n("自动检测index路径,下拉式选择(dropdown)"),
1082
+ choices=sorted(index_paths),
1083
+ interactive=True,
1084
+ visible=False
1085
+ )
1086
+ refresh_button.click(
1087
+ fn=lambda: change_choices()[1],
1088
+ inputs=[],
1089
+ outputs=file_index4,
1090
+ api_name="infer_refresh_batch",
1091
+ )
1092
+ # file_big_npy2 = gr.Textbox(
1093
+ # label=i18n("特征文件路径"),
1094
+ # value="E:\\codes\\py39\\vits_vc_gpu_train\\logs\\mi-test-1key\\total_fea.npy",
1095
+ # interactive=True,
1096
+ # )
1097
+ index_rate2 = gr.Slider(
1098
+ minimum=0,
1099
+ maximum=1,
1100
+ label=i18n("检索特征占比"),
1101
+ value=1,
1102
+ interactive=True,
1103
+ visible=False
1104
+ )
1105
+ with gr.Row():
1106
+ resample_sr1 = gr.Slider(
1107
+ minimum=0,
1108
+ maximum=48000,
1109
+ label=i18n("后处理重采样至最终采样率,0为不进行重采样"),
1110
+ value=0,
1111
+ step=1,
1112
+ interactive=True,
1113
+ visible=False
1114
+ )
1115
+ rms_mix_rate1 = gr.Slider(
1116
+ minimum=0,
1117
+ maximum=1,
1118
+ label=i18n("输入源音量包络替换输出音量包络融合比例,越靠近1越使用输出包络"),
1119
+ value=0.21,
1120
+ interactive=True,
1121
+ )
1122
+ protect1 = gr.Slider(
1123
+ minimum=0,
1124
+ maximum=0.5,
1125
+ label=i18n(
1126
+ "保护清辅音和呼吸声,防止电音撕裂等artifact,拉满0.5不开启,调低加大保护力度但可能降低索引效果"
1127
+ ),
1128
+ value=0.33,
1129
+ step=0.01,
1130
+ interactive=True,
1131
+ )
1132
+ with gr.Row():
1133
+ dir_input = gr.Textbox(
1134
+ label=i18n("输入待处理音频文件夹路径(去文件管理器地址栏拷就行了)"),
1135
+ value="./audios",
1136
+ )
1137
+ inputs = gr.File(
1138
+ file_count="multiple", label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹")
1139
+ )
1140
+ with gr.Row():
1141
+ format1 = gr.Radio(
1142
+ label=i18n("导出文件格式"),
1143
+ choices=["wav", "flac", "mp3", "m4a"],
1144
+ value="wav",
1145
+ interactive=True,
1146
+ )
1147
+ but1 = gr.Button(i18n("转换"), variant="primary")
1148
+ vc_output3 = gr.Textbox(label=i18n("输出信息"))
1149
+ but1.click(
1150
+ vc.vc_multi,
1151
+ [
1152
+ spk_item,
1153
+ dir_input,
1154
+ opt_input,
1155
+ inputs,
1156
+ vc_transform1,
1157
+ f0method1,
1158
+ file_index1,
1159
+ file_index2,
1160
+ # file_big_npy2,
1161
+ index_rate1,
1162
+ filter_radius1,
1163
+ resample_sr1,
1164
+ rms_mix_rate1,
1165
+ protect1,
1166
+ format1,
1167
+ ],
1168
+ [vc_output3],
1169
+ api_name="infer_convert_batch",
1170
+ )
1171
+ sid0.change(
1172
+ fn=vc.get_vc,
1173
+ inputs=[sid0, protect0, protect1],
1174
+ outputs=[spk_item, protect0, protect1, file_index2, file_index4],
1175
+ )
1176
+ with gr.TabItem("Download Model"):
1177
+ with gr.Row():
1178
+ url=gr.Textbox(label="Enter the URL to the Model:")
1179
+ with gr.Row():
1180
+ model = gr.Textbox(label="Name your model:")
1181
+ download_button=gr.Button("Download")
1182
+ with gr.Row():
1183
+ status_bar=gr.Textbox(label="")
1184
+ download_button.click(fn=download_from_url, inputs=[url, model], outputs=[status_bar])
1185
+ with gr.Row():
1186
+ gr.Markdown(
1187
+ """
1188
+ ❤️ If you use this and like it, help me keep it.❤️
1189
+ https://paypal.me/lesantillan
1190
+ """
1191
+ )
1192
+ with gr.TabItem(i18n("训练")):
1193
+ with gr.Row():
1194
+ with gr.Column():
1195
+ exp_dir1 = gr.Textbox(label=i18n("输入实验名"), value="My-Voice")
1196
+ np7 = gr.Slider(
1197
+ minimum=0,
1198
+ maximum=config.n_cpu,
1199
+ step=1,
1200
+ label=i18n("提取音高和处理数据使用的CPU进程数"),
1201
+ value=int(np.ceil(config.n_cpu / 1.5)),
1202
+ interactive=True,
1203
+ )
1204
+ sr2 = gr.Radio(
1205
+ label=i18n("目标采样率"),
1206
+ choices=["40k", "48k"],
1207
+ value="40k",
1208
+ interactive=True,
1209
+ visible=False
1210
+ )
1211
+ if_f0_3 = gr.Radio(
1212
+ label=i18n("模型是否带音高指导(唱歌一定要, 语音可以不要)"),
1213
+ choices=[True, False],
1214
+ value=True,
1215
+ interactive=True,
1216
+ visible=False
1217
+ )
1218
+ version19 = gr.Radio(
1219
+ label=i18n("版本"),
1220
+ choices=["v1", "v2"],
1221
+ value="v2",
1222
+ interactive=True,
1223
+ visible=False,
1224
+ )
1225
+ trainset_dir4 = gr.Textbox(
1226
+ label=i18n("输入训练文件夹路径"), value='./dataset/'+datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
1227
+ )
1228
+ easy_uploader = gr.Files(label=i18n("也可批量输入音频文件, 二选一, 优先读文件夹"),file_types=['audio'])
1229
+ but1 = gr.Button(i18n("处理数据"), variant="primary")
1230
+ info1 = gr.Textbox(label=i18n("输出信息"), value="")
1231
+ easy_uploader.upload(fn=upload_to_dataset, inputs=[easy_uploader, trainset_dir4], outputs=[info1, trainset_dir4])
1232
+ gpus6 = gr.Textbox(
1233
+ label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1234
+ value=gpus,
1235
+ interactive=True,
1236
+ visible=F0GPUVisible,
1237
+ )
1238
+ gpu_info9 = gr.Textbox(
1239
+ label=i18n("显卡信息"), value=gpu_info, visible=F0GPUVisible
1240
+ )
1241
+ spk_id5 = gr.Slider(
1242
+ minimum=0,
1243
+ maximum=4,
1244
+ step=1,
1245
+ label=i18n("请指定说话人id"),
1246
+ value=0,
1247
+ interactive=True,
1248
+ visible=False
1249
+ )
1250
+ but1.click(
1251
+ preprocess_dataset,
1252
+ [trainset_dir4, exp_dir1, sr2, np7],
1253
+ [info1],
1254
+ api_name="train_preprocess",
1255
+ )
1256
+ with gr.Column():
1257
+ f0method8 = gr.Radio(
1258
+ label=i18n(
1259
+ "选择音高提取算法:输入歌声可用pm提速,高质量语音但CPU差可用dio提速,harvest质量更好但慢,rmvpe效果最好且微吃CPU/GPU"
1260
+ ),
1261
+ choices=["pm", "harvest", "dio", "rmvpe", "rmvpe_gpu"],
1262
+ value="rmvpe_gpu",
1263
+ interactive=True,
1264
+ )
1265
+ gpus_rmvpe = gr.Textbox(
1266
+ label=i18n(
1267
+ "rmvpe卡号配置:以-分隔输入使用的不同进程卡号,例如0-0-1使用在卡0上跑2个进程并在卡1上跑1个进程"
1268
+ ),
1269
+ value="%s-%s" % (gpus, gpus),
1270
+ interactive=True,
1271
+ visible=F0GPUVisible,
1272
+ )
1273
+ but2 = gr.Button(i18n("特征提取"), variant="primary")
1274
+ info2 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=8)
1275
+ f0method8.change(
1276
+ fn=change_f0_method,
1277
+ inputs=[f0method8],
1278
+ outputs=[gpus_rmvpe],
1279
+ )
1280
+ but2.click(
1281
+ extract_f0_feature,
1282
+ [
1283
+ gpus6,
1284
+ np7,
1285
+ f0method8,
1286
+ if_f0_3,
1287
+ exp_dir1,
1288
+ version19,
1289
+ gpus_rmvpe,
1290
+ ],
1291
+ [info2],
1292
+ api_name="train_extract_f0_feature",
1293
+ )
1294
+ with gr.Column():
1295
+ total_epoch11 = gr.Slider(
1296
+ minimum=2,
1297
+ maximum=1000,
1298
+ step=1,
1299
+ label=i18n("总训练轮数total_epoch"),
1300
+ value=150,
1301
+ interactive=True,
1302
+ )
1303
+ gpus16 = gr.Textbox(
1304
+ label=i18n("以-分隔输入使用的卡号, 例如 0-1-2 使用卡0和卡1和卡2"),
1305
+ value="0",
1306
+ interactive=True,
1307
+ visible=True
1308
+ )
1309
+ but3 = gr.Button(i18n("训练模型"), variant="primary")
1310
+ but4 = gr.Button(i18n("训练特征索引"), variant="primary")
1311
+ info3 = gr.Textbox(label=i18n("输出信息"), value="", max_lines=10)
1312
+ with gr.Accordion(label=i18n("常规设置"), open=False):
1313
+ save_epoch10 = gr.Slider(
1314
+ minimum=1,
1315
+ maximum=50,
1316
+ step=1,
1317
+ label=i18n("保存频率save_every_epoch"),
1318
+ value=25,
1319
+ interactive=True,
1320
+ )
1321
+ batch_size12 = gr.Slider(
1322
+ minimum=1,
1323
+ maximum=40,
1324
+ step=1,
1325
+ label=i18n("每张显卡的batch_size"),
1326
+ value=default_batch_size,
1327
+ interactive=True,
1328
+ )
1329
+ if_save_latest13 = gr.Radio(
1330
+ label=i18n("是否仅保存最新的ckpt文件以节省硬盘空间"),
1331
+ choices=[i18n("是"), i18n("否")],
1332
+ value=i18n("是"),
1333
+ interactive=True,
1334
+ visible=False
1335
+ )
1336
+ if_cache_gpu17 = gr.Radio(
1337
+ label=i18n(
1338
+ "是否缓存所有训练集至显存. 10min以下小数据可缓存以加速训练, 大数据缓存会炸显存也加不了多少速"
1339
+ ),
1340
+ choices=[i18n("是"), i18n("否")],
1341
+ value=i18n("否"),
1342
+ interactive=True,
1343
+ )
1344
+ if_save_every_weights18 = gr.Radio(
1345
+ label=i18n("是否在每次保存时间点将最终小模型保存至weights文件夹"),
1346
+ choices=[i18n("是"), i18n("否")],
1347
+ value=i18n("是"),
1348
+ interactive=True,
1349
+ )
1350
+ with gr.Row():
1351
+ download_model = gr.Button('5.Download Model')
1352
+ with gr.Row():
1353
+ model_files = gr.Files(label='Your Model and Index file can be downloaded here:')
1354
+ download_model.click(fn=download_model_files, inputs=[exp_dir1], outputs=[model_files, info3])
1355
+ with gr.Row():
1356
+ pretrained_G14 = gr.Textbox(
1357
+ label=i18n("加载预训练底模G路径"),
1358
+ value="assets/pretrained_v2/f0G40k.pth",
1359
+ interactive=True,
1360
+ visible=False
1361
+ )
1362
+ pretrained_D15 = gr.Textbox(
1363
+ label=i18n("加载预训练底模D路径"),
1364
+ value="assets/pretrained_v2/f0D40k.pth",
1365
+ interactive=True,
1366
+ visible=False
1367
+ )
1368
+ sr2.change(
1369
+ change_sr2,
1370
+ [sr2, if_f0_3, version19],
1371
+ [pretrained_G14, pretrained_D15],
1372
+ )
1373
+ version19.change(
1374
+ change_version19,
1375
+ [sr2, if_f0_3, version19],
1376
+ [pretrained_G14, pretrained_D15, sr2],
1377
+ )
1378
+ if_f0_3.change(
1379
+ change_f0,
1380
+ [if_f0_3, sr2, version19],
1381
+ [f0method8, pretrained_G14, pretrained_D15],
1382
+ )
1383
+ with gr.Row():
1384
+ but5 = gr.Button(i18n("一键训练"), variant="primary", visible=False)
1385
+ but3.click(
1386
+ click_train,
1387
+ [
1388
+ exp_dir1,
1389
+ sr2,
1390
+ if_f0_3,
1391
+ spk_id5,
1392
+ save_epoch10,
1393
+ total_epoch11,
1394
+ batch_size12,
1395
+ if_save_latest13,
1396
+ pretrained_G14,
1397
+ pretrained_D15,
1398
+ gpus16,
1399
+ if_cache_gpu17,
1400
+ if_save_every_weights18,
1401
+ version19,
1402
+ ],
1403
+ info3,
1404
+ api_name="train_start",
1405
+ )
1406
+ but4.click(train_index, [exp_dir1, version19], info3)
1407
+ but5.click(
1408
+ train1key,
1409
+ [
1410
+ exp_dir1,
1411
+ sr2,
1412
+ if_f0_3,
1413
+ trainset_dir4,
1414
+ spk_id5,
1415
+ np7,
1416
+ f0method8,
1417
+ save_epoch10,
1418
+ total_epoch11,
1419
+ batch_size12,
1420
+ if_save_latest13,
1421
+ pretrained_G14,
1422
+ pretrained_D15,
1423
+ gpus16,
1424
+ if_cache_gpu17,
1425
+ if_save_every_weights18,
1426
+ version19,
1427
+ gpus_rmvpe,
1428
+ ],
1429
+ info3,
1430
+ api_name="train_start_all",
1431
+ )
1432
+
1433
+ if config.iscolab:
1434
+ app.queue(concurrency_count=511, max_size=1022).launch(share=True)
1435
+ else:
1436
+ app.queue(concurrency_count=511, max_size=1022).launch(
1437
+ server_name="0.0.0.0",
1438
+ inbrowser=not config.noautoopen,
1439
+ server_port=config.listen_port,
1440
+ quiet=True,
1441
+ )
assets/hubert/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *
2
+ !.gitignore
assets/hubert/hubert_base.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f54b40fd2802423a5643779c4861af1e9ee9c1564dc9d32f54f20b5ffba7db96
3
+ size 189507909
assets/pretrained/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *
2
+ !.gitignore
assets/pretrained_v2/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *
2
+ !.gitignore
assets/pretrained_v2/D40k.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:471378e894e7191f89a94eda8288c5947b16bbe0b10c3f1f17efdb7a1d998242
3
+ size 142875703
assets/pretrained_v2/G40k.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3843da7fde33db1dab176146c70d6c2df06eafe9457f4e3aa10024e9c6a4b69
3
+ size 72959671
assets/pretrained_v2/f0D40k.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6b6ab091e70801b28e3f41f335f2fc5f3f35c75b39ae2628d419644ec2b0fa09
3
+ size 142875703
assets/pretrained_v2/f0G40k.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b2c44035e782c4b14ddc0bede9e2f4a724d025cd073f736d4f43708453adfcb
3
+ size 73106273
assets/rmvpe/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *
2
+ !.gitignore
assets/rmvpe/rmvpe.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5ed4719f59085d1affc5d81354c70828c740584f2d24e782523345a6a278962
3
+ size 181189687
assets/uvr5_weights/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *
2
+ !.gitignore
assets/weights/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *
2
+ !.gitignore
assets/weights/MJV2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3554bbb4916e7bf54526ff7eb63f8016b679c6a81074c63e28778c86dbb5cba
3
+ size 55192782
assets/weights/MJV2_e100_s100.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ad1ad8e0e934ddaea5c2c0df2bc520c567a7dceba3e65c23ddd6feed2ae0f46
3
+ size 55226492
assets/weights/MJV2_e120_s120.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e9f9d7d649161f25e8ac54a559aaa262682b1bea7e1840961ef0e0436dd1b361
3
+ size 55226492
assets/weights/MJV2_e140_s140.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e7f3f9fb6a07ecf1b63de606c355068705f21445c1b6fc818c779d6312b854d
3
+ size 55226492
assets/weights/MJV2_e160_s160.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:903217c53b53a4700561abab0cfea198ebfaa816875dfbddc1b334771167ea71
3
+ size 55226492
assets/weights/MJV2_e180_s180.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5821ffc7d73a66a125a1bad3a3d9f7d51aff383a1a665358b1743ac6e98b5efe
3
+ size 55226492
assets/weights/MJV2_e200_s200.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c6fc3ffaf1ebb7473035dcd9f5ac90102fe00b79dd7fd03bd22f6530aaa528b
3
+ size 55226492
assets/weights/MJV2_e20_s20.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fe47ad05b191636d760d7cd6d4831e6f0fde820260c789a1842aff12c32f49c3
3
+ size 55225574
assets/weights/MJV2_e220_s220.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:76874e3abd5e7e7529fc853ee5169e4e0cbf923a6103105e27bf604df5369011
3
+ size 55226492
assets/weights/MJV2_e240_s240.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6be8f2d881f78809757a101136667d29106d10fc039fc95304ca15bffa23fdd
3
+ size 55226492
assets/weights/MJV2_e260_s260.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22430c9230f0a2b7a6c18226790dcf1ded2bee9377c44a0b43027535af9004e8
3
+ size 55226492
assets/weights/MJV2_e280_s280.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5469a8cefdf4eb1a131994a355bbfb000e728f7ea776d84b02165815a490d5df
3
+ size 55226492
assets/weights/MJV2_e300_s300.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0330a419b71671ec97cd92aea9445177f937b67b67c0af5fec5081a440489282
3
+ size 55226492
assets/weights/MJV2_e40_s40.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91b9ef9001966ca8c46fb32b2c522e9c6aba9034e5c070be3e3e87fa1d96608b
3
+ size 55225574
assets/weights/MJV2_e60_s60.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d8f64fe3cd9e479695e7be77560888ef23685c9e9df9beb1826589c3209da00
3
+ size 55225574
assets/weights/MJV2_e80_s80.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38c7fbb917e72379212491ab0b0b5685896f262aa58e38f212a63603c0622874
3
+ size 55225574
audios/somegirl.mp3 ADDED
Binary file (32.2 kB). View file
 
audios/someguy.mp3 ADDED
Binary file (24.9 kB). View file
 
audios/unachica.mp3 ADDED
Binary file (36.4 kB). View file
 
audios/unchico.mp3 ADDED
Binary file (35.9 kB). View file
 
configs/__pycache__/config.cpython-310.pyc ADDED
Binary file (5.18 kB). View file