From 1105edea6d8db014de2414ce67e9725ff2853625 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 20:44:42 +0200 Subject: [PATCH 01/40] - Added main.yml --- .github/workflows/main.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b70686c --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,25 @@ +name: Python CI + +on: + push: + branches: + - CI + pull_request: + branches: + - CI + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: 3.10 + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run tests + run: pytest From 4e4f83e39e276f111b536cd7bab19e1c4afc8ba3 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 20:58:53 +0200 Subject: [PATCH 02/40] - Try fix py version 3.10 definition --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b70686c..cc51c2c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v2 with: - python-version: 3.10 + python-version: '3.10' - name: Install dependencies run: pip install -r requirements.txt From 40a327ab5c781b8878c7c88620a9266436bbe617 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 21:11:04 +0200 Subject: [PATCH 03/40] - Path to the requirements.txt --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cc51c2c..a42d946 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,7 @@ jobs: python-version: '3.10' - name: Install dependencies - run: pip install -r requirements.txt + run: pip install -r ../../requirements.txt - name: Run tests run: pytest From 3d2d2e21a7d67582ed8bc574ae2e6731d7993d9f Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 21:18:14 +0200 Subject: [PATCH 04/40] - test the path --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a42d946..6c2c5e5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,9 @@ jobs: with: python-version: '3.10' + - name: List directory contents + run: ls -R + - name: Install dependencies run: pip install -r ../../requirements.txt From a3802e85c45b746fa276eb08f219dce2f0390b4a Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 21:29:08 +0200 Subject: [PATCH 05/40] - Add Checkout step --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6c2c5e5..ce0cbbb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,14 +13,14 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Set up Python 3.10 uses: actions/setup-python@v2 with: python-version: '3.10' - - name: List directory contents - run: ls -R - - name: Install dependencies run: pip install -r ../../requirements.txt From 46d5f52970e9e824c3c0cfb4df1f32f4c607c167 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 21:30:00 +0200 Subject: [PATCH 06/40] - revert dependency relative path --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ce0cbbb..a83e043 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: python-version: '3.10' - name: Install dependencies - run: pip install -r ../../requirements.txt + run: pip install -r requirements.txt - name: Run tests run: pytest From 2ed52b68b947ae6fa7eb34ab66ab4c372a57f0bf Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 21:41:03 +0200 Subject: [PATCH 07/40] - remove test step --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a83e043..01fba31 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,6 +23,3 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - - - name: Run tests - run: pytest From f3900185ba98cbf3e49276a42de4331879ff165d Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 28 May 2023 23:30:19 +0200 Subject: [PATCH 08/40] - Added Build Badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a28ccb9..b271aa5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Discord](https://img.shields.io/discord/1048892118732656731?logo=discord)](https://discord.gg/7EqhhjFd) ![Status](https://img.shields.io/badge/status-development-yellow) +![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rakuri255/UltraSinger/main.yml) [![GitHub](https://img.shields.io/github/license/rakuri255/UltraSinger)](https://github.com/rakuri255/UltraSinger/blob/main/LICENSE) # UltraSinger From a5ab270658c2d45988ff72e13713697bb989601c Mon Sep 17 00:00:00 2001 From: Vadim Rangnau <36919102+rakuri255@users.noreply.github.com> Date: Thu, 1 Jun 2023 11:24:27 +0200 Subject: [PATCH 09/40] Update main.yml --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01fba31..d32f2e2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,3 +23,6 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt + + - name: Install gpu dependencies + run: pip3 install torch~=2.0.1+cu117 torchvision~=0.15.2+cu117 torchaudio~=2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 From 928bc95e0bae3ce1fd6ff88415914a72e0055c6f Mon Sep 17 00:00:00 2001 From: Vadim Rangnau <36919102+rakuri255@users.noreply.github.com> Date: Thu, 1 Jun 2023 11:31:12 +0200 Subject: [PATCH 10/40] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d32f2e2..a0d7658 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,4 +25,4 @@ jobs: run: pip install -r requirements.txt - name: Install gpu dependencies - run: pip3 install torch~=2.0.1+cu117 torchvision~=0.15.2+cu117 torchaudio~=2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 + run: pip3 install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 From 2b106b58d0812c50df6510de3bec448bb22ef970 Mon Sep 17 00:00:00 2001 From: Vadim Rangnau <36919102+rakuri255@users.noreply.github.com> Date: Wed, 7 Jun 2023 14:03:44 +0200 Subject: [PATCH 11/40] Update main.yml --- .github/workflows/main.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a0d7658..34412e8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,14 +10,22 @@ on: jobs: build: - runs-on: ubuntu-latest - + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + TARGET: Linux + #- os: macos-latest + #TARGET: macOS + - os: windows-latest + TARGET: Windows steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python 3.10 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: '3.10' From f6f15b5fcddb93d1d9b62404c02680b2b7160bee Mon Sep 17 00:00:00 2001 From: Vadim Rangnau <36919102+rakuri255@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:01:50 +0200 Subject: [PATCH 12/40] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 34412e8..68112dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,8 @@ jobs: include: - os: ubuntu-latest TARGET: Linux - #- os: macos-latest - #TARGET: macOS + - os: macos-latest + TARGET: macOS - os: windows-latest TARGET: Windows steps: From d12641aedb8258477cb71091ac27995623f28bd8 Mon Sep 17 00:00:00 2001 From: Vadim Rangnau <36919102+rakuri255@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:49:57 +0200 Subject: [PATCH 13/40] Update main.yml --- .github/workflows/main.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68112dd..69a71a1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,8 @@ jobs: include: - os: ubuntu-latest TARGET: Linux - - os: macos-latest - TARGET: macOS + #- os: macos-latest + # TARGET: macOS - os: windows-latest TARGET: Windows steps: @@ -34,3 +34,6 @@ jobs: - name: Install gpu dependencies run: pip3 install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 + + - name: pylinter + uses: programmingwithalex/pylinter@v1.4.3 From e2005d1bc3c1d3ead731b7d4a23e4d81a617846b Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 16:35:47 +0200 Subject: [PATCH 14/40] - separate pylint --- .github/workflows/main.yml | 3 --- .github/workflows/pylint.yml | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69a71a1..a86dbc1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,3 @@ jobs: - name: Install gpu dependencies run: pip3 install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 - - - name: pylinter - uses: programmingwithalex/pylinter@v1.4.3 diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..1781766 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,14 @@ +name: PyLint + +on: [push, pull_request] + +jobs: + python-lint: + runs-on: ubuntu-latest + name: CI workflow + steps: + - name: checkout source repo + uses: actions/checkout@main + + - name: linting + uses: rakuri255/UltraSinger@main \ No newline at end of file From 0676377877301399d84247c486d04a83bbb1d7bd Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 16:37:16 +0200 Subject: [PATCH 15/40] - change checkout for pylint --- .github/workflows/pylint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 1781766..df5d4b1 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,8 +7,8 @@ jobs: runs-on: ubuntu-latest name: CI workflow steps: - - name: checkout source repo - uses: actions/checkout@main + - name: Checkout repository + uses: actions/checkout@v3 - name: linting uses: rakuri255/UltraSinger@main \ No newline at end of file From 257fc2805cd5ac0e4f9f38eaf37ac109dc556eae Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 16:37:36 +0200 Subject: [PATCH 16/40] - add mac --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a86dbc1..68112dd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,8 +16,8 @@ jobs: include: - os: ubuntu-latest TARGET: Linux - #- os: macos-latest - # TARGET: macOS + - os: macos-latest + TARGET: macOS - os: windows-latest TARGET: Windows steps: From 30ae050de7bc4f406aa260802dc01cfa6b251622 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 22:48:54 +0200 Subject: [PATCH 17/40] - downgrade vosk for mac --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f6f4116..0d4f689 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ pretty_midi==0.2.9 pydub==0.25.1 Levenshtein==0.20.9 scipy==1.10.0 -vosk==0.3.45 +vosk==0.3.44 tensorflow~=2.12.0 matplotlib~=3.7.1 yt_dlp~=2023.3.4 From 7cee4445eec9d81b8bd1987fbc7708443ac39a49 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 22:58:30 +0200 Subject: [PATCH 18/40] - try fix --- .github/workflows/main.yml | 7 +++++++ .github/workflows/pylint.yml | 3 +++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 68112dd..6e782dc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,14 +23,21 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + repository: rakuri255/UltraSinger + path: UltraSinger - name: Set up Python 3.10 uses: actions/setup-python@v4 + working-directory: UltraSinger with: python-version: '3.10' - name: Install dependencies + working-directory: UltraSinger run: pip install -r requirements.txt - name: Install gpu dependencies + if: matrix.TARGET != 'macOS' + working-directory: UltraSinger run: pip3 install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index df5d4b1..bf4505d 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -9,6 +9,9 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + repository: rakuri255/UltraSinger + path: UltraSinger - name: linting uses: rakuri255/UltraSinger@main \ No newline at end of file From 925cc75f80a7a36a3285ca638db4d6c70d1f1256 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 23:08:33 +0200 Subject: [PATCH 19/40] - try fix --- .github/workflows/main.yml | 3 --- .github/workflows/pylint.yml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6e782dc..0ade343 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,15 +29,12 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v4 - working-directory: UltraSinger with: python-version: '3.10' - name: Install dependencies - working-directory: UltraSinger run: pip install -r requirements.txt - name: Install gpu dependencies if: matrix.TARGET != 'macOS' - working-directory: UltraSinger run: pip3 install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index bf4505d..33aa9ca 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -8,7 +8,7 @@ jobs: name: CI workflow steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v2 with: repository: rakuri255/UltraSinger path: UltraSinger From 82e7eb07e344be200becc169a3f949814be9f368 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 23:15:57 +0200 Subject: [PATCH 20/40] - try fix --- .github/workflows/main.yml | 8 +++++--- .github/workflows/pylint.yml | 7 ++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0ade343..fc18433 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,9 +4,14 @@ on: push: branches: - CI + paths: + #- "requirements.txt" + pull_request: branches: - CI + paths: + #- "requirements.txt" jobs: build: @@ -23,9 +28,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - with: - repository: rakuri255/UltraSinger - path: UltraSinger - name: Set up Python 3.10 uses: actions/setup-python@v4 diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 33aa9ca..d498f22 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -8,10 +8,7 @@ jobs: name: CI workflow steps: - name: Checkout repository - uses: actions/checkout@v2 - with: - repository: rakuri255/UltraSinger - path: UltraSinger + uses: actions/checkout@CI - name: linting - uses: rakuri255/UltraSinger@main \ No newline at end of file + uses: rakuri255/UltraSinger@CI \ No newline at end of file From c428be0bd251ba16a6aa11b49b195bcddfdea39c Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 23:26:49 +0200 Subject: [PATCH 21/40] - try fix --- .github/workflows/main.yml | 10 +++------- .github/workflows/pylint.yml | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fc18433..d23a0e7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,17 +1,13 @@ -name: Python CI +name: Check Requirements on: push: - branches: - - CI paths: - #- "requirements.txt" + - "requirements.txt" pull_request: - branches: - - CI paths: - #- "requirements.txt" + - "requirements.txt" jobs: build: diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index d498f22..7b7f6c9 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,14 +1,23 @@ name: PyLint -on: [push, pull_request] +#on: [push, pull_request] +on: + push: + branches: + - CI + paths: + #- "requirements.txt" + + pull_request: + branches: + - CI + paths: + #- "requirements.txt" jobs: - python-lint: + build: runs-on: ubuntu-latest - name: CI workflow steps: - - name: Checkout repository - uses: actions/checkout@CI - - - name: linting + - uses: actions/checkout@v2 + - name: Python Linter uses: rakuri255/UltraSinger@CI \ No newline at end of file From 8953e4f51577452e7eb6080619a45010223d3181 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 23:31:10 +0200 Subject: [PATCH 22/40] - try fix --- .github/workflows/main.yml | 4 +++- .github/workflows/pylint.yml | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d23a0e7..d88209f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,6 +21,8 @@ jobs: TARGET: macOS - os: windows-latest TARGET: Windows + python-version: [ "3.10" ] + steps: - name: Checkout repository uses: actions/checkout@v3 @@ -28,7 +30,7 @@ jobs: - name: Set up Python 3.10 uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: ${{ matrix.python-version }} - name: Install dependencies run: pip install -r requirements.txt diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 7b7f6c9..5abdb30 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,23 +1,23 @@ -name: PyLint +name: Pylint -#on: [push, pull_request] -on: - push: - branches: - - CI - paths: - #- "requirements.txt" - - pull_request: - branches: - - CI - paths: - #- "requirements.txt" +on: [push] jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] steps: - - uses: actions/checkout@v2 - - name: Python Linter - uses: rakuri255/UltraSinger@CI \ No newline at end of file + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') From b8778fcf286c1ce3365a83ba9cb61fd3463d5de6 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 23:36:40 +0200 Subject: [PATCH 23/40] - added pylint badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 61a804b..fc4328c 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rakuri255/UltraSinger/main.yml) [![GitHub](https://img.shields.io/github/license/rakuri255/UltraSinger)](https://github.com/rakuri255/UltraSinger/blob/main/LICENSE) [![CodeFactor](https://www.codefactor.io/repository/github/rakuri255/ultrasinger/badge)](https://www.codefactor.io/repository/github/rakuri255/ultrasinger) +[![Pylint](https://github.com/rakuri255/UltraSinger/actions/workflows/pylint.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/pylint.yml) # UltraSinger From 5279a594836173ee2e799c1874c5d4e19abb6900 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 7 Jun 2023 23:37:39 +0200 Subject: [PATCH 24/40] - Trigger test --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 0d4f689..0bef095 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ Pillow~=9.5.0 isort==5.12 black==23.3 pylint==2.17 +# \ No newline at end of file From 251b507dbcfead7214e4a1a4d65ea6aeb62417e8 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 00:13:25 +0200 Subject: [PATCH 25/40] - Init pytest --- .github/workflows/pylint.yml | 6 ++++- .github/workflows/pytest.yml | 25 +++++++++++++++++++ README.md | 3 ++- .../UltraStar/test_ultrastar_converter.py | 24 ++++++++++++++++++ requirements.txt | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/pytest.yml create mode 100644 pytest/modules/UltraStar/test_ultrastar_converter.py diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 5abdb30..f306e1a 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -9,15 +9,19 @@ jobs: matrix: python-version: ["3.10"] steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip pip install pylint + - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..9969ba5 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,25 @@ +name: Pytest + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.10" ] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Run pytest + run: pytest diff --git a/README.md b/README.md index fc4328c..5db6c40 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rakuri255/UltraSinger/main.yml) [![GitHub](https://img.shields.io/github/license/rakuri255/UltraSinger)](https://github.com/rakuri255/UltraSinger/blob/main/LICENSE) [![CodeFactor](https://www.codefactor.io/repository/github/rakuri255/ultrasinger/badge)](https://www.codefactor.io/repository/github/rakuri255/ultrasinger) -[![Pylint](https://github.com/rakuri255/UltraSinger/actions/workflows/pylint.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/pylint.yml) + +[![Check Requirements](https://github.com/rakuri255/UltraSinger/actions/workflows/main.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/main.yml) # UltraSinger diff --git a/pytest/modules/UltraStar/test_ultrastar_converter.py b/pytest/modules/UltraStar/test_ultrastar_converter.py new file mode 100644 index 0000000..9f5760d --- /dev/null +++ b/pytest/modules/UltraStar/test_ultrastar_converter.py @@ -0,0 +1,24 @@ +"""Tests for ultrastar_converter.py""" + +from modules.Ultrastar.ultrastar_converter import real_bpm_to_ultrastar_bpm + + +def test_real_bpm_to_ultrastar_bpm(): + """Test case for real_bpm_to_ultrastar_bpm function.""" + # Real BPM is a multiple of 4 + assert real_bpm_to_ultrastar_bpm(120) == 30 + + # Real BPM is not a multiple of 4 + assert real_bpm_to_ultrastar_bpm(130) == 32.5 + + # Real BPM is zero + assert real_bpm_to_ultrastar_bpm(0) == 0 + + # Real BPM is a decimal number + assert real_bpm_to_ultrastar_bpm(123.45) == 30.8625 + + # Real BPM is a large number + assert real_bpm_to_ultrastar_bpm(1000000) == 250000 + + # Real BPM is a small number + assert real_bpm_to_ultrastar_bpm(0.001) == 0.00025 diff --git a/requirements.txt b/requirements.txt index 0bef095..6275777 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,4 @@ Pillow~=9.5.0 isort==5.12 black==23.3 pylint==2.17 -# \ No newline at end of file +pytest~=7.3.1 \ No newline at end of file From ceb58c1bea14ece7972a2384ee62ad23fffb8c84 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 12:04:11 +0200 Subject: [PATCH 26/40] - refactor --- Settings.py | 1 - UltraSinger.py | 180 +++++++++--------- modules/Audio/silence_processing.py | 3 +- modules/DeviceDetection/device_detection.py | 16 +- modules/Midi/midi_creator.py | 32 ++-- modules/Pitcher/pitched_data.py | 10 +- modules/Pitcher/pitcher.py | 44 +---- modules/Speech_Recognition/Vosk.py | 6 +- modules/Speech_Recognition/Whisper.py | 6 +- modules/Speech_Recognition/hyphenation.py | 14 +- modules/Ultrastar/ultrastar_converter.py | 35 ++-- modules/Ultrastar/ultrastar_parser.py | 6 +- .../Ultrastar/ultrastar_score_calculator.py | 24 +-- modules/Ultrastar/ultrastar_txt.py | 6 +- modules/Ultrastar/ultrastar_writer.py | 47 ++--- modules/csv_export.py | 24 --- modules/csv_handler.py | 47 +++++ modules/os_helper.py | 30 +-- 18 files changed, 273 insertions(+), 258 deletions(-) delete mode 100644 modules/csv_export.py create mode 100644 modules/csv_handler.py diff --git a/Settings.py b/Settings.py index 09c271a..a025f14 100644 --- a/Settings.py +++ b/Settings.py @@ -29,4 +29,3 @@ class Settings: device = 'cpu' # cpu|cuda force_whisper_cpu = False force_separation_cpu = False - diff --git a/UltraSinger.py b/UltraSinger.py index 5f4ece7..04d75bd 100644 --- a/UltraSinger.py +++ b/UltraSinger.py @@ -5,6 +5,7 @@ import getopt import os import sys from time import sleep +from typing import Tuple, Any import Levenshtein import librosa @@ -19,7 +20,7 @@ from modules.Audio.vocal_chunks import ( export_chunks_from_ultrastar_data, ) from modules.Audio.silence_processing import remove_silence_from_transcribtion_data -from modules.csv_export import export_transcribed_data_to_csv +from modules.csv_handler import export_transcribed_data_to_csv from modules.Audio.convert_audio import convert_audio_to_mono_wav, convert_wav_to_mp3 from modules.Audio.youtube import ( download_youtube_audio, @@ -45,6 +46,7 @@ from modules.Pitcher.pitcher import ( get_frequency_with_high_confidence, get_pitch_with_crepe_file, ) +from modules.Pitcher.pitched_data import PitchedData from modules.Speech_Recognition.hyphenation import hyphenation, language_check from modules.Speech_Recognition.Vosk import transcribe_with_vosk from modules.Speech_Recognition.Whisper import transcribe_with_whisper @@ -56,12 +58,13 @@ from modules.Ultrastar import ( ) from modules.Ultrastar.ultrastar_txt import UltrastarTxt from Settings import Settings +from modules.Speech_Recognition.TranscribedData import TranscribedData settings = Settings() -def get_confidence(pitched_data, threshold): - """Docstring""" +def get_confidence(pitched_data: PitchedData, threshold: float) -> tuple[list[float], list[float], list[float]]: + """Get high confidence data""" # todo: replace get_frequency_with_high_conf from pitcher conf_t = [] conf_f = [] @@ -75,8 +78,8 @@ def get_confidence(pitched_data, threshold): return conf_t, conf_f, conf_c -def convert_ultrastar_note_numbers(midi_notes): - """Docstring""" +def convert_midi_notes_to_ultrastar_notes(midi_notes: list[str]) -> list[int]: + """Convert midi notes to ultrastar notes""" print(f"{ULTRASINGER_HEAD} Creating Ultrastar notes from midi data") ultrastar_note_numbers = [] @@ -93,8 +96,8 @@ def convert_ultrastar_note_numbers(midi_notes): return ultrastar_note_numbers -def pitch_each_chunk_with_crepe(directory): - """Docstring""" +def pitch_each_chunk_with_crepe(directory: str) -> list[str]: + """Pitch each chunk with crepe and return midi notes""" print( f"{ULTRASINGER_HEAD} Pitching each chunk with {blue_highlighted('crepe')}" ) @@ -123,8 +126,8 @@ def pitch_each_chunk_with_crepe(directory): return midi_notes -def add_hyphen_to_data(transcribed_data, hyphen_words): - """Docstring""" +def add_hyphen_to_data(transcribed_data: list[TranscribedData], hyphen_words: list[list[str]]): + """Add hyphen to transcribed data return new data list""" new_data = [] for i, data in enumerate(transcribed_data): @@ -150,7 +153,7 @@ def add_hyphen_to_data(transcribed_data, hyphen_words): def get_bpm_from_data(data, sampling_rate): - """Docstring""" + """Get real bpm from audio data""" onset_env = librosa.onset.onset_strength(y=data, sr=sampling_rate) wav_tempo = librosa.beat.tempo(onset_envelope=onset_env, sr=sampling_rate) @@ -160,8 +163,8 @@ def get_bpm_from_data(data, sampling_rate): return wav_tempo[0] -def get_bpm_from_file(wav_file): - """Docstring""" +def get_bpm_from_file(wav_file: str): + """Get real bpm from audio file""" data, sampling_rate = librosa.load(wav_file, sr=None) return get_bpm_from_data(data, sampling_rate) @@ -184,8 +187,8 @@ def correct_words(recognized_words, word_list_file): return recognized_words -def print_help(): - """Docstring""" +def print_help() -> None: + """Print help text""" help_string = """ UltraSinger.py [opt] [mode] [transcription] [pitcher] [extra] @@ -226,8 +229,8 @@ def print_help(): print(help_string) -def plot(input_file, vosk_transcribed_data, midi_notes): - """Docstring""" +def plot(input_file: str, transcribed_data: list[TranscribedData], midi_notes: list[str]) -> None: + """Plot transcribed data""" pitched_data = get_pitch_with_crepe_file( input_file, settings.crepe_step_size, settings.crepe_model_capacity ) @@ -238,7 +241,7 @@ def plot(input_file, vosk_transcribed_data, midi_notes): plt.plot(conf_t, conf_f, linewidth=0.1) plt.savefig(os.path.join("test", "crepe_0.4.png")) - for i, data in enumerate(vosk_transcribed_data): + for i, data in enumerate(transcribed_data): note_frequency = librosa.note_to_hz(midi_notes[i]) plt.plot( [data.start, data.end], @@ -249,8 +252,8 @@ def plot(input_file, vosk_transcribed_data, midi_notes): plt.savefig(os.path.join("test", "pit.png"), dpi=2000) -def remove_unecessary_punctuations(transcribed_data): - """Docstring""" +def remove_unecessary_punctuations(transcribed_data: list[TranscribedData]) -> None: + """Remove unecessary punctuations from transcribed data""" punctuation = ".," for i, data in enumerate(transcribed_data): data.word = data.word.translate( @@ -258,8 +261,8 @@ def remove_unecessary_punctuations(transcribed_data): ) -def hyphenate_each_word(language, transcribed_data): - """Docstring""" +def hyphenate_each_word(language: str, transcribed_data: list[TranscribedData]) -> list[list[str]] | None: + """Hyphenate each word in the transcribed data.""" hyphenated_word = [] lang_region = language_check(language) if lang_region is None: @@ -276,8 +279,8 @@ def hyphenate_each_word(language, transcribed_data): return hyphenated_word -def print_support(): - """Docstring""" +def print_support() -> None: + """Print support text""" print() print( f"{ULTRASINGER_HEAD} {gold_highlighted('Do you like UltraSinger? And want it to be even better? Then help with your')} {light_blue_highlighted('support')}{gold_highlighted('!')}" @@ -290,8 +293,8 @@ def print_support(): ) -def run(): - """Docstring""" +def run() -> None: + """The processing function of this program""" is_audio = ".txt" not in settings.input_file_path ultrastar_class = None real_bpm = None @@ -324,7 +327,7 @@ def run(): basename_without_ext, song_output, ultrastar_audio_input_path, - ) = setup_audio_input_file() + ) = infos_from_audio_input_file() cache_path = os.path.join(song_output, "cache") settings.mono_audio_path = os.path.join( @@ -344,7 +347,7 @@ def run(): transcribed_data = None language = None if is_audio: - language, transcribed_data = transcribe_audio(transcribed_data) + language, transcribed_data = transcribe_audio() remove_unecessary_punctuations(transcribed_data) transcribed_data = remove_silence_from_transcribtion_data( settings.mono_audio_path, transcribed_data @@ -414,8 +417,8 @@ def run(): print_support() -def get_unused_song_output_dir(path): - """Docstring""" +def get_unused_song_output_dir(path: str) -> str: + """Get an unused song output dir""" # check if dir exists and add (i) if it does i = 1 if os_helper.check_if_folder_exists(path): @@ -434,8 +437,8 @@ def get_unused_song_output_dir(path): return path -def transcribe_audio(transcribed_data): - """Docstring""" +def transcribe_audio() -> (str, list[TranscribedData]): + """Transcribe audio with AI""" if settings.transcriber == "whisper": device = "cpu" if settings.force_whisper_cpu else settings.device transcribed_data, language = transcribe_with_whisper( @@ -450,9 +453,9 @@ def transcribe_audio(transcribed_data): def separate_vocal_from_audio( - basename_without_ext, cache_path, ultrastar_audio_input_path -): - """Docstring""" + basename_without_ext: str, cache_path: str, ultrastar_audio_input_path: str +) -> str: + """Separate vocal from audio""" audio_separation_path = os.path.join( cache_path, "separated", "htdemucs", basename_without_ext ) @@ -470,9 +473,9 @@ def separate_vocal_from_audio( def calculate_score_points( - is_audio, pitched_data, ultrastar_class, ultrastar_file_output + is_audio: bool, pitched_data: PitchedData, ultrastar_class: UltrastarTxt, ultrastar_file_output: str ): - """Docstring""" + """Calculate score points""" if is_audio: ultrastar_class = ultrastar_parser.parse_ultrastar_txt( ultrastar_file_output @@ -518,9 +521,9 @@ def calculate_score_points( def create_ultrastar_txt_from_ultrastar_data( - song_output, ultrastar_class, ultrastar_note_numbers -): - """Docstring""" + song_output: str, ultrastar_class: UltrastarTxt, ultrastar_note_numbers: list[int] +) -> str: + """Create Ultrastar txt from Ultrastar data""" output_repitched_ultrastar = os.path.join( song_output, ultrastar_class.title + ".txt" ) @@ -533,15 +536,15 @@ def create_ultrastar_txt_from_ultrastar_data( def create_ultrastar_txt_from_automation( - audio_separation_path, - basename_without_ext, - song_output, - transcribed_data, - ultrastar_audio_input_path, - ultrastar_note_numbers, - language, + audio_separation_path: str, + basename_without_ext: str, + song_output: str, + transcribed_data: list[TranscribedData], + ultrastar_audio_input_path: str, + ultrastar_note_numbers: list[int], + language: str, ): - """Docstring""" + """Create Ultrastar txt from automation""" ultrastar_header = UltrastarTxt() ultrastar_header.title = basename_without_ext ultrastar_header.artist = basename_without_ext @@ -585,8 +588,8 @@ def create_ultrastar_txt_from_automation( return real_bpm, ultrastar_file_output -def setup_audio_input_file(): - """Docstring""" +def infos_from_audio_input_file() -> tuple[str, str, str]: + """Infos from audio input file""" basename = os.path.basename(settings.input_file_path) basename_without_ext = os.path.splitext(basename)[0] song_output = os.path.join(settings.output_file_path, basename_without_ext) @@ -601,7 +604,7 @@ FILENAME_REPLACEMENTS = (('?:"', ""), ("<", "("), (">", ")"), ("/\\|*", "-")) def sanitize_filename(fname: str) -> str: - """Docstring""" + """Sanitize filename""" for old, new in FILENAME_REPLACEMENTS: for char in old: fname = fname.replace(char, new) @@ -610,8 +613,8 @@ def sanitize_filename(fname: str) -> str: return fname -def download_from_youtube(): - """Docstring""" +def download_from_youtube() -> tuple[str, str, str]: + """Download from YouTube""" title = get_youtube_title(settings.input_file_path) basename_without_ext = sanitize_filename(title) basename = basename_without_ext + ".mp3" @@ -631,8 +634,8 @@ def download_from_youtube(): return basename_without_ext, song_output, ultrastar_audio_input_path -def parse_ultrastar_txt(): - """Docstring""" +def parse_ultrastar_txt() -> tuple[str, float, str, str, UltrastarTxt]: + """Parse Ultrastar txt""" ultrastar_class = ultrastar_parser.parse_ultrastar_txt( settings.input_file_path ) @@ -658,8 +661,8 @@ def parse_ultrastar_txt(): ) -def create_midi_file(is_audio, real_bpm, song_output, ultrastar_class): - """Docstring""" +def create_midi_file(is_audio: bool, real_bpm: float, song_output: str, ultrastar_class: UltrastarTxt) -> None: + """Create midi file""" print( f"{ULTRASINGER_HEAD} Creating Midi with {blue_highlighted('pretty_midi')}" ) @@ -681,8 +684,8 @@ def create_midi_file(is_audio, real_bpm, song_output, ultrastar_class): ) -def pitch_audio(is_audio, transcribed_data, ultrastar_class): - """Docstring""" +def pitch_audio(is_audio: bool, transcribed_data: list[TranscribedData], ultrastar_class: UltrastarTxt): + """Pitch audio""" # todo: chunk pitching as option? # midi_notes = pitch_each_chunk_with_crepe(chunk_folder_name) pitched_data = get_pitch_with_crepe_file( @@ -704,18 +707,18 @@ def pitch_audio(is_audio, transcribed_data, ultrastar_class): midi_notes = create_midi_notes_from_pitched_data( ultrastar_class.startTimes, ultrastar_class.endTimes, pitched_data ) - ultrastar_note_numbers = convert_ultrastar_note_numbers(midi_notes) + ultrastar_note_numbers = convert_midi_notes_to_ultrastar_notes(midi_notes) return midi_notes, pitched_data, ultrastar_note_numbers def create_audio_chunks( - cache_path, - is_audio, - transcribed_data, - ultrastar_audio_input_path, - ultrastar_class, -): - """Docstring""" + cache_path: str, + is_audio: bool, + transcribed_data: list[TranscribedData], + ultrastar_audio_input_path: str, + ultrastar_class: UltrastarTxt +) -> None: + """Create audio chunks""" audio_chunks_path = os.path.join( cache_path, settings.audio_chunk_folder_name ) @@ -732,8 +735,8 @@ def create_audio_chunks( ) -def denoise_vocal_audio(basename_without_ext, cache_path): - """Docstring""" +def denoise_vocal_audio(basename_without_ext: str, cache_path: str) -> None: + """Denoise vocal audio""" denoised_path = os.path.join( cache_path, basename_without_ext + "_denoised.wav" ) @@ -741,30 +744,17 @@ def denoise_vocal_audio(basename_without_ext, cache_path): settings.mono_audio_path = denoised_path -def main(argv): - """Docstring""" +def main(argv: list[str]) -> None: + """Main function""" init_settings(argv) run() # todo: cleanup sys.exit() -def init_settings(argv): - """Docstring""" - short = "hi:o:amv:" - long = [ - "ifile=", - "ofile=", - "crepe=", - "vosk=", - "whisper=", - "hyphenation=", - "disable_separation=", - "disable_karaoke=", - "create_audio_chunks=", - "force_whisper_cpu=", - "force_separation_cpu=" - ] +def init_settings(argv: list[str]) -> None: + """Init settings""" + long, short = arg_options() opts, args = getopt.getopt(argv, short, long) if len(opts) == 0: print_help() @@ -806,5 +796,23 @@ def init_settings(argv): settings.device = get_available_device() +def arg_options(): + short = "hi:o:amv:" + long = [ + "ifile=", + "ofile=", + "crepe=", + "vosk=", + "whisper=", + "hyphenation=", + "disable_separation=", + "disable_karaoke=", + "create_audio_chunks=", + "force_whisper_cpu=", + "force_separation_cpu=" + ] + return long, short + + if __name__ == "__main__": main(sys.argv[1:]) diff --git a/modules/Audio/silence_processing.py b/modules/Audio/silence_processing.py index c140555..e139547 100644 --- a/modules/Audio/silence_processing.py +++ b/modules/Audio/silence_processing.py @@ -3,9 +3,10 @@ import librosa from modules.console_colors import ULTRASINGER_HEAD +from modules.Speech_Recognition.TranscribedData import TranscribedData -def remove_silence_from_transcribtion_data(audio_path: str, transcribed_data: []) -> []: +def remove_silence_from_transcribtion_data(audio_path: str, transcribed_data: list[TranscribedData]) -> list[TranscribedData]: """Remove silence from given transcribtion data""" print( diff --git a/modules/DeviceDetection/device_detection.py b/modules/DeviceDetection/device_detection.py index a4b97e2..5912438 100644 --- a/modules/DeviceDetection/device_detection.py +++ b/modules/DeviceDetection/device_detection.py @@ -1,21 +1,19 @@ -"""Docstring""" +"""Device detection module.""" import torch from modules.console_colors import ULTRASINGER_HEAD, red_highlighted -def get_available_device(): - """Docstring""" - isCuda = torch.cuda.is_available() +def get_available_device() -> str: + """Get available worker device e.g cuda or cpu""" + is_cuda = torch.cuda.is_available() - if not isCuda: + if not is_cuda: print( f"{ULTRASINGER_HEAD} There are no {red_highlighted('cuda')} devices available. -> Using {red_highlighted('cpu')}." ) - return "cpu" - else: - print(f"{ULTRASINGER_HEAD} Using {red_highlighted('cuda')} GPU.") + print(f"{ULTRASINGER_HEAD} Using {red_highlighted('cuda')} GPU.") - return "cuda" \ No newline at end of file + return "cuda" diff --git a/modules/Midi/midi_creator.py b/modules/Midi/midi_creator.py index 0141148..ee4aa75 100644 --- a/modules/Midi/midi_creator.py +++ b/modules/Midi/midi_creator.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Midi creator module""" import math from collections import Counter @@ -17,10 +17,12 @@ from modules.console_colors import ( ULTRASINGER_HEAD, red_highlighted, ) +from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Pitcher.pitched_data import PitchedData -def convert_ultrastar_to_midi_instrument(ultrastar_class): - """Docstring""" +def convert_ultrastar_to_midi_instrument(ultrastar_class: UltrastarTxt) -> object: + """Converts an Ultrastar data to a midi instrument""" print(f"{ULTRASINGER_HEAD} Creating midi instrument from Ultrastar txt") @@ -39,8 +41,8 @@ def convert_ultrastar_to_midi_instrument(ultrastar_class): return instrument -def instruments_to_midi(instruments, bpm, midi_output): - """Docstring""" +def instruments_to_midi(instruments: list[object], bpm: float, midi_output: str) -> None: + """Write instruments to midi file""" print(f"{ULTRASINGER_HEAD} Creating midi file -> {midi_output}") @@ -54,21 +56,21 @@ class MidiCreator: """Docstring""" -def convert_frequencies_to_notes(frequency): - """Docstring""" +def convert_frequencies_to_notes(frequency: [str]) -> list[list[str]]: + """Converts frequencies to notes""" notes = [] for freq in frequency: notes.append(librosa.hz_to_note(float(freq))) return notes -def most_frequent(array): - """Docstring""" +def most_frequent(array: [str]) -> list[tuple[str, int]]: + """Get most frequent item in array""" return Counter(array).most_common(1) -def find_nearest_index(array, value): - """Docstring""" +def find_nearest_index(array: list[float], value: float) -> int: + """Nearest index in array""" idx = np.searchsorted(array, value, side="left") if idx > 0 and ( idx == len(array) @@ -79,8 +81,8 @@ def find_nearest_index(array, value): return idx -def create_midi_notes_from_pitched_data(start_times, end_times, pitched_data): - """Docstring""" +def create_midi_notes_from_pitched_data(start_times: list[float], end_times: list[float], pitched_data: PitchedData) -> list[str]: + """Create midi notes from pitched data""" print(f"{ULTRASINGER_HEAD} Creating midi notes from pitched data") midi_notes = [] @@ -100,8 +102,8 @@ def create_midi_notes_from_pitched_data(start_times, end_times, pitched_data): return midi_notes -def create_midi_note_from_pitched_data(start_time, end_time, pitched_data): - """Docstring""" +def create_midi_note_from_pitched_data(start_time: float, end_time: float, pitched_data: PitchedData) -> str: + """Create midi note from pitched data""" start = find_nearest_index(pitched_data.times, start_time) end = find_nearest_index(pitched_data.times, end_time) diff --git a/modules/Pitcher/pitched_data.py b/modules/Pitcher/pitched_data.py index 0b7b620..574192f 100644 --- a/modules/Pitcher/pitched_data.py +++ b/modules/Pitcher/pitched_data.py @@ -1,9 +1,9 @@ -"""Docstring""" +"""Pitched data""" class PitchedData: - """Docstring""" + """Pitched data from crepe""" - times = [] - frequencies = [] - confidence = [] + times = list[float] + frequencies = list[float] + confidence = list[float] diff --git a/modules/Pitcher/pitcher.py b/modules/Pitcher/pitcher.py index 39d2837..2d17c67 100644 --- a/modules/Pitcher/pitcher.py +++ b/modules/Pitcher/pitcher.py @@ -1,6 +1,4 @@ -"""Docstring""" - -import csv +"""Pitcher module""" import crepe from scipy.io import wavfile @@ -13,8 +11,8 @@ from modules.console_colors import ( from modules.Pitcher.pitched_data import PitchedData -def get_pitch_with_crepe_file(filename, step_size, model_capacity): - """Docstring""" +def get_pitch_with_crepe_file(filename: str, step_size: int, model_capacity: str) -> PitchedData: + """Pitch with crepe""" print( f"{ULTRASINGER_HEAD} Pitching with {blue_highlighted('crepe')} and model {blue_highlighted(model_capacity)} and {red_highlighted('cpu')} as worker" ) @@ -33,8 +31,8 @@ def get_pitch_with_crepe_file(filename, step_size, model_capacity): return pitched_data -def get_pitch_with_crepe(audio, sample_rate, step_size, model_capacity): - """Docstring""" +def get_pitch_with_crepe(audio, sample_rate: int, step_size: int, model_capacity: str) -> PitchedData: + """Pitch with crepe""" pitched_data = PitchedData() ( pitched_data.times, @@ -47,36 +45,14 @@ def get_pitch_with_crepe(audio, sample_rate, step_size, model_capacity): return pitched_data -def write_lists_to_csv(times, frequencies, confidences, filename): - """Docstring""" - with open(filename, "w", encoding="utf-8", newline="") as csvfile: - writer = csv.writer(csvfile) - header = ["time", "frequency", "confidence"] - writer.writerow(header) - for i in enumerate(times): - pos = i[0] - writer.writerow([times[pos], frequencies[pos], confidences[pos]]) - - -def read_data_from_csv(filename): - """Docstring""" - csv_data = [] - with open(filename, "r", encoding="utf-8") as csv_file: - csv_reader = csv.reader(csv_file) - for line in csv_reader: - csv_data.append(line) - headless_data = csv_data[1:] - return headless_data - - -def get_frequency_with_high_confidence(freqs, confs, threshold=0.4): - """Docstring""" +def get_frequency_with_high_confidence(frequencies: list[float], confidences: list[float], threshold=0.4) -> list[float]: + """Get frequency with high confidence""" conf_f = [] - for i, conf in enumerate(confs): + for i, conf in enumerate(confidences): if conf > threshold: - conf_f.append(freqs[i]) + conf_f.append(frequencies[i]) if not conf_f: - conf_f = freqs + conf_f = frequencies return conf_f diff --git a/modules/Speech_Recognition/Vosk.py b/modules/Speech_Recognition/Vosk.py index 0f1c0b7..08d77e5 100644 --- a/modules/Speech_Recognition/Vosk.py +++ b/modules/Speech_Recognition/Vosk.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Vosk speech recognition module.""" import json import wave @@ -11,8 +11,8 @@ from modules.Speech_Recognition.TranscribedData import TranscribedData # todo: Rename to Transcoder? -def transcribe_with_vosk(audio_filename, model_path): - """Docstring""" +def transcribe_with_vosk(audio_filename: str, model_path: str) -> list[TranscribedData]: + """Transcribe with vosk""" # Code from here: https://towardsdatascience.com/speech-recognition-with-timestamps-934ede4234b2 print( f"{ULTRASINGER_HEAD} Transcribing {audio_filename} with vosk and model {model_path}" diff --git a/modules/Speech_Recognition/Whisper.py b/modules/Speech_Recognition/Whisper.py index 09d1e0e..e452673 100644 --- a/modules/Speech_Recognition/Whisper.py +++ b/modules/Speech_Recognition/Whisper.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Whisper Speech Recognition Module""" import whisperx @@ -10,8 +10,8 @@ from modules.console_colors import ( from modules.Speech_Recognition.TranscribedData import TranscribedData -def transcribe_with_whisper(audio_path, model, device="cpu"): - """Docstring""" +def transcribe_with_whisper(audio_path: str, model: str, device="cpu") -> (list[TranscribedData], str): + """Transcribe with whisper""" print( f"{ULTRASINGER_HEAD} Loading {blue_highlighted('whisper')} with model {blue_highlighted(model)} and {red_highlighted(device)} as worker" diff --git a/modules/Speech_Recognition/hyphenation.py b/modules/Speech_Recognition/hyphenation.py index 89f7009..a04f214 100644 --- a/modules/Speech_Recognition/hyphenation.py +++ b/modules/Speech_Recognition/hyphenation.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Hyphenation module""" import string @@ -10,8 +10,8 @@ from modules.console_colors import ( ) -def language_check(language="en"): - """Docstring""" +def language_check(language="en") -> str | None: + """Check if language is supported""" dict_langs = dictools.LANGUAGES @@ -30,14 +30,14 @@ def language_check(language="en"): return lang_region -def contains_punctuation(word): - """Docstring""" +def contains_punctuation(word: str) -> bool: + """Check if word contains punctuation""" return any(elem in word for elem in string.punctuation) -def hyphenation(word, lang_region): - """Docstring""" +def hyphenation(word: str, lang_region: str) -> list[str] | None: + """Hyphenate word""" if contains_punctuation(word): return None diff --git a/modules/Ultrastar/ultrastar_converter.py b/modules/Ultrastar/ultrastar_converter.py index 2bc1239..ce15c93 100644 --- a/modules/Ultrastar/ultrastar_converter.py +++ b/modules/Ultrastar/ultrastar_converter.py @@ -1,22 +1,23 @@ -"""Docstring""" +"""Ultrastar Converter""" +from modules.Ultrastar.ultrastar_txt import UltrastarTxt -def real_bpm_to_ultrastar_bpm(real_bpm): - """Docstring""" +def real_bpm_to_ultrastar_bpm(real_bpm: float) -> float: + """Converts real BPM to UltraStar BPM""" # The UltraStar BPM info is a fifth beat of the real BPM ultrastar_bpm = real_bpm / 4 return ultrastar_bpm -def ultrastar_bpm_to_real_bpm(ultrastar_bpm): - """Docstring""" +def ultrastar_bpm_to_real_bpm(ultrastar_bpm: float) -> float: + """Converts UltraStar BPM to real BPM""" # The UltraStar BPM info is a fifth beat of the real BPM bpm = ultrastar_bpm * 4 return bpm -def second_to_beat(seconds, real_bpm): - """Docstring""" +def second_to_beat(seconds: float, real_bpm: float) -> float: + """Converts seconds to beat""" # BPM = 60 * beat / T # T * BPM = 60 * beat # beat = T * BPM / 60 @@ -24,31 +25,31 @@ def second_to_beat(seconds, real_bpm): return beat -def beat_to_second(beat, real_bpm): - """Docstring""" +def beat_to_second(beat: float, real_bpm: float) -> float: + """Converts beat to seconds""" seconds = beat * 60 / real_bpm return seconds -def midi_note_to_ultrastar_note(midi_note): - """Docstring""" +def midi_note_to_ultrastar_note(midi_note: int) -> int: + """Converts Midi note to UltraStar note""" # C4 == 48 in Midi ultrastar_note = midi_note - 48 return ultrastar_note -def ultrastar_note_to_midi_note(ultrastar_note): - """Docstring""" +def ultrastar_note_to_midi_note(ultrastar_note: int) -> int: + """Converts UltraStar note to Midi note""" # C4 == 48 in Midi midi_note = ultrastar_note + 48 return midi_note -def get_start_time_from_ultrastar(ultrastar_class, pos): - """Docstring""" +def get_start_time_from_ultrastar(ultrastar_class: UltrastarTxt, pos: int) -> float: + """Calculates the start time from the Ultrastar txt""" gap = int(ultrastar_class.gap) / 1000 real_bpm = ultrastar_bpm_to_real_bpm( @@ -60,8 +61,8 @@ def get_start_time_from_ultrastar(ultrastar_class, pos): return start_time -def get_end_time_from_ultrastar(ultrastar_class, pos): - """Docstring""" +def get_end_time_from_ultrastar(ultrastar_class: UltrastarTxt, pos: int) -> float: + """Calculates the end time from the Ultrastar txt""" gap = int(ultrastar_class.gap) / 1000 real_bpm = ultrastar_bpm_to_real_bpm( diff --git a/modules/Ultrastar/ultrastar_parser.py b/modules/Ultrastar/ultrastar_parser.py index e68ab30..0af6ec2 100644 --- a/modules/Ultrastar/ultrastar_parser.py +++ b/modules/Ultrastar/ultrastar_parser.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Ultrastar txt parser""" from modules.console_colors import ULTRASINGER_HEAD from modules.Ultrastar.ultrastar_converter import ( @@ -8,8 +8,8 @@ from modules.Ultrastar.ultrastar_converter import ( from modules.Ultrastar.ultrastar_txt import UltrastarTxt -def parse_ultrastar_txt(input_file): - """Docstring""" +def parse_ultrastar_txt(input_file: str) -> UltrastarTxt: + """Parse ultrastar txt file to UltrastarTxt class""" print(f"{ULTRASINGER_HEAD} Parse ultrastar txt -> {input_file}") with open(input_file, "r", encoding="utf-8") as file: diff --git a/modules/Ultrastar/ultrastar_score_calculator.py b/modules/Ultrastar/ultrastar_score_calculator.py index 20fe33b..b789dd0 100644 --- a/modules/Ultrastar/ultrastar_score_calculator.py +++ b/modules/Ultrastar/ultrastar_score_calculator.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Ultrastar score calculator.""" import librosa @@ -16,6 +16,8 @@ from modules.Ultrastar.ultrastar_converter import ( get_start_time_from_ultrastar, ultrastar_note_to_midi_note, ) +from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Pitcher.pitched_data import PitchedData MAX_SONG_SCORE = 10000 MAX_SONG_LINE_BONUS = 1000 @@ -32,8 +34,8 @@ class Points: parts = 0 -def add_point(note_type, points): - """Docstring""" +def add_point(note_type: str, points: Points) -> Points: + """Add calculated points to the points object.""" if note_type == ":": points.notes += 1 @@ -56,8 +58,8 @@ class Score: score = 0 -def get_score(points): - """Docstring""" +def get_score(points: Points) -> Score: + """Score calculation.""" score = Score() score.max_score = ( @@ -74,16 +76,16 @@ def get_score(points): return score -def print_score(score): - """Docstring""" +def print_score(score: Score) -> None: + """Print score.""" print( f"{ULTRASINGER_HEAD} Total: {cyan_highlighted(str(score.score))}, notes: {blue_highlighted(str(score.notes))}, line bonus: {light_blue_highlighted(str(score.line_bonus))}, golden notes: {gold_highlighted(str(score.golden))}" ) -def calculate_score(pitched_data, ultrastar_class): - """Docstring""" +def calculate_score(pitched_data: PitchedData, ultrastar_class: UltrastarTxt) -> (Score, Score): + """Calculate score.""" print(ULTRASINGER_HEAD + " Calculating Ultrastar Points") @@ -150,8 +152,8 @@ def calculate_score(pitched_data, ultrastar_class): return get_score(simple_points), get_score(accurate_points) -def print_score_calculation(simple_points, accurate_points): - """Docstring""" +def print_score_calculation(simple_points: Score, accurate_points: Score) -> None: + """Print score calculation.""" print( f"{ULTRASINGER_HEAD} {underlined('Simple (octave high ignored)')} points" diff --git a/modules/Ultrastar/ultrastar_txt.py b/modules/Ultrastar/ultrastar_txt.py index 7425378..f29b64e 100644 --- a/modules/Ultrastar/ultrastar_txt.py +++ b/modules/Ultrastar/ultrastar_txt.py @@ -7,11 +7,13 @@ class UltrastarTxt: artist = "" title = "" mp3 = "" + video = None gap = "" bpm = "" + language = None cover = None creator = "UltraSinger [GitHub]" - fixer = "YOUR NAME" # Only for UltraStar World Party + fixer = "YOUR NAME" # Only for UltraStar World Party comment = "UltraSinger [GitHub]" startBeat = [] startTimes = [] @@ -19,4 +21,4 @@ class UltrastarTxt: durations = [] pitches = [] words = [] - noteType = [] + noteType = [] # F, R, G, *, : diff --git a/modules/Ultrastar/ultrastar_writer.py b/modules/Ultrastar/ultrastar_writer.py index 8304ae4..ba197f1 100644 --- a/modules/Ultrastar/ultrastar_writer.py +++ b/modules/Ultrastar/ultrastar_writer.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""Ultrastar writer module""" import re @@ -9,10 +9,13 @@ from modules.Ultrastar.ultrastar_converter import ( real_bpm_to_ultrastar_bpm, second_to_beat, ) +from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Speech_Recognition.TranscribedData import TranscribedData +from modules.Ultrastar.ultrastar_score_calculator import Score -def get_multiplier(real_bpm): - """Docstring""" +def get_multiplier(real_bpm: float) -> int: + """Calculates the multiplier for the BPM""" if real_bpm == 0: raise Exception("BPM is 0") @@ -25,20 +28,20 @@ def get_multiplier(real_bpm): return multiplier - 2 -def get_language_name(language): - """Docstring""" +def get_language_name(language: str) -> str: + """Creates the language name from the language code""" return langcodes.Language.make(language=language).display_name() def create_ultrastar_txt_from_automation( - transcribed_data, - note_numbers, - ultrastar_file_output, - ultrastar_class, - bpm=120, -): - """Docstring""" + transcribed_data: list[TranscribedData], + note_numbers: list[int], + ultrastar_file_output: str, + ultrastar_class: UltrastarTxt, + bpm=120, +) -> None: + """Creates an Ultrastar txt file from the automation data""" print( f"{ULTRASINGER_HEAD} Creating {ultrastar_file_output} from transcription." @@ -72,8 +75,8 @@ def create_ultrastar_txt_from_automation( for i, data in enumerate(transcribed_data): start_time = (data.start - gap) * multiplication end_time = ( - data.end - data.start - ) * multiplication + data.end - data.start + ) * multiplication start_beat = round(second_to_beat(start_time, bpm)) duration = round(second_to_beat(end_time, bpm)) @@ -97,7 +100,7 @@ def create_ultrastar_txt_from_automation( # detect silence between words if i < len(transcribed_data) - 1: silence = ( - transcribed_data[i + 1].start - data.end + transcribed_data[i + 1].start - data.end ) else: silence = 0 @@ -108,8 +111,8 @@ def create_ultrastar_txt_from_automation( # 'n1' show next at time in real beat file.write("- ") show_next = ( - second_to_beat(data.end - gap, bpm) - * multiplication + second_to_beat(data.end - gap, bpm) + * multiplication ) file.write(str(round(show_next))) file.write("\n") @@ -117,9 +120,9 @@ def create_ultrastar_txt_from_automation( def create_repitched_txt_from_ultrastar_data( - input_file, note_numbers, output_repitched_ultrastar -): - """Docstring""" + input_file: str, note_numbers: list[int], output_repitched_ultrastar: str +) -> None: + """Creates a repitched ultrastar txt file from the original one""" # todo: just add '_repitched' to input_file print( "{PRINT_ULTRASTAR} Creating repitched ultrastar txt -> {input_file}_repitch.txt" @@ -149,8 +152,8 @@ def create_repitched_txt_from_ultrastar_data( file.write(line) -def add_score_to_ultrastar_txt(ultrastar_file_output, score): - """Docstring""" +def add_score_to_ultrastar_txt(ultrastar_file_output: str, score: Score) -> None: + """Adds the score to the ultrastar txt file""" with open(ultrastar_file_output, "r", encoding="utf-8") as file: text = file.read() text = text.split("\n") diff --git a/modules/csv_export.py b/modules/csv_export.py deleted file mode 100644 index 680507e..0000000 --- a/modules/csv_export.py +++ /dev/null @@ -1,24 +0,0 @@ -"""CSV export module""" - -import csv - -from modules.console_colors import ULTRASINGER_HEAD - - -def export_transcribed_data_to_csv(transcribed_data: [], filename: str) -> None: - """Export transcribed data to csv""" - print(f"{ULTRASINGER_HEAD} Exporting transcribed data to CSV") - - with open(filename, "w", encoding="utf-8", newline="") as csvfile: - writer = csv.writer(csvfile) - header = ["word", "start", "end", "confidence"] - writer.writerow(header) - for i, data in enumerate(transcribed_data): - writer.writerow( - [ - data.word, - data.start, - data.end, - data.conf, - ] - ) diff --git a/modules/csv_handler.py b/modules/csv_handler.py new file mode 100644 index 0000000..58cceeb --- /dev/null +++ b/modules/csv_handler.py @@ -0,0 +1,47 @@ +"""CSV export module""" + +import csv + +from modules.console_colors import ULTRASINGER_HEAD +from modules.Speech_Recognition.TranscribedData import TranscribedData + + +def export_transcribed_data_to_csv(transcribed_data: list[TranscribedData], filename: str) -> None: + """Export transcribed data to csv""" + print(f"{ULTRASINGER_HEAD} Exporting transcribed data to CSV") + + with open(filename, "w", encoding="utf-8", newline="") as csvfile: + writer = csv.writer(csvfile) + header = ["word", "start", "end", "confidence"] + writer.writerow(header) + for i, data in enumerate(transcribed_data): + writer.writerow( + [ + data.word, + data.start, + data.end, + data.conf, + ] + ) + + +def write_lists_to_csv(times, frequencies, confidences, filename: str): + """Write lists to csv""" + with open(filename, "w", encoding="utf-8", newline="") as csvfile: + writer = csv.writer(csvfile) + header = ["time", "frequency", "confidence"] + writer.writerow(header) + for i in enumerate(times): + pos = i[0] + writer.writerow([times[pos], frequencies[pos], confidences[pos]]) + + +def read_data_from_csv(filename: str): + """Read data from csv""" + csv_data = [] + with open(filename, "r", encoding="utf-8") as csv_file: + csv_reader = csv.reader(csv_file) + for line in csv_reader: + csv_data.append(line) + headless_data = csv_data[1:] + return headless_data diff --git a/modules/os_helper.py b/modules/os_helper.py index 8f2f9bd..cc0a7c5 100644 --- a/modules/os_helper.py +++ b/modules/os_helper.py @@ -1,4 +1,4 @@ -"""Docstring""" +"""OS helper functions.""" import os import shutil @@ -6,39 +6,39 @@ import shutil from modules.console_colors import ULTRASINGER_HEAD -def create_folder(folder_name): - """Docstring""" +def create_folder(folder_name: str) -> None: + """Creates a folder if it doesn't exist.""" print(f"{ULTRASINGER_HEAD} Creating output folder. -> {folder_name}") is_exist = os.path.exists(folder_name) if not is_exist: os.makedirs(folder_name) -def move(original, target): - """Docstring""" +def move(original: str, target: str) -> None: + """Moves a file from one location to another.""" shutil.move(original, target) -def copy(original, target): - """Docstring""" +def copy(original:str, target: str) -> None: + """Copies a file from one location to another.""" shutil.copy(original, target) -def current_executor_path(): - """Docstring""" +def current_executor_path() -> str: + """Current executor path""" return os.getcwd() -def path_join(path1, path2): - """Docstring""" +def path_join(path1: str, path2: str) -> str: + """Joins two paths together""" return os.path.join(path1, path2) -def check_file_exists(file_path): - """Docstring""" +def check_file_exists(file_path: str) -> bool: + """Checks if a file exists.""" return os.path.isfile(file_path) -def check_if_folder_exists(song_output): - """Docstring""" +def check_if_folder_exists(song_output: str) -> bool: + """Checks if a folder exists.""" return os.path.isdir(song_output) From baead46b589e250197e0b636b7643084dcef960c Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 12:53:14 +0200 Subject: [PATCH 27/40] - refactor ultrastar txt with enums --- UltraSinger.py | 16 ++--- modules/Audio/vocal_chunks.py | 4 +- modules/Midi/midi_creator.py | 4 +- modules/Ultrastar/ultrastar_converter.py | 6 +- modules/Ultrastar/ultrastar_parser.py | 26 ++++---- .../Ultrastar/ultrastar_score_calculator.py | 4 +- modules/Ultrastar/ultrastar_txt.py | 63 +++++++++++++++++-- modules/Ultrastar/ultrastar_writer.py | 55 ++++++++-------- 8 files changed, 121 insertions(+), 57 deletions(-) diff --git a/UltraSinger.py b/UltraSinger.py index 04d75bd..773da64 100644 --- a/UltraSinger.py +++ b/UltraSinger.py @@ -56,7 +56,7 @@ from modules.Ultrastar import ( ultrastar_score_calculator, ultrastar_writer, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue from Settings import Settings from modules.Speech_Recognition.TranscribedData import TranscribedData @@ -473,7 +473,7 @@ def separate_vocal_from_audio( def calculate_score_points( - is_audio: bool, pitched_data: PitchedData, ultrastar_class: UltrastarTxt, ultrastar_file_output: str + is_audio: bool, pitched_data: PitchedData, ultrastar_class: UltrastarTxtValue, ultrastar_file_output: str ): """Calculate score points""" if is_audio: @@ -521,7 +521,7 @@ def calculate_score_points( def create_ultrastar_txt_from_ultrastar_data( - song_output: str, ultrastar_class: UltrastarTxt, ultrastar_note_numbers: list[int] + song_output: str, ultrastar_class: UltrastarTxtValue, ultrastar_note_numbers: list[int] ) -> str: """Create Ultrastar txt from Ultrastar data""" output_repitched_ultrastar = os.path.join( @@ -545,7 +545,7 @@ def create_ultrastar_txt_from_automation( language: str, ): """Create Ultrastar txt from automation""" - ultrastar_header = UltrastarTxt() + ultrastar_header = UltrastarTxtValue() ultrastar_header.title = basename_without_ext ultrastar_header.artist = basename_without_ext ultrastar_header.mp3 = basename_without_ext + ".mp3" @@ -634,7 +634,7 @@ def download_from_youtube() -> tuple[str, str, str]: return basename_without_ext, song_output, ultrastar_audio_input_path -def parse_ultrastar_txt() -> tuple[str, float, str, str, UltrastarTxt]: +def parse_ultrastar_txt() -> tuple[str, float, str, str, UltrastarTxtValue]: """Parse Ultrastar txt""" ultrastar_class = ultrastar_parser.parse_ultrastar_txt( settings.input_file_path @@ -661,7 +661,7 @@ def parse_ultrastar_txt() -> tuple[str, float, str, str, UltrastarTxt]: ) -def create_midi_file(is_audio: bool, real_bpm: float, song_output: str, ultrastar_class: UltrastarTxt) -> None: +def create_midi_file(is_audio: bool, real_bpm: float, song_output: str, ultrastar_class: UltrastarTxtValue) -> None: """Create midi file""" print( f"{ULTRASINGER_HEAD} Creating Midi with {blue_highlighted('pretty_midi')}" @@ -684,7 +684,7 @@ def create_midi_file(is_audio: bool, real_bpm: float, song_output: str, ultrasta ) -def pitch_audio(is_audio: bool, transcribed_data: list[TranscribedData], ultrastar_class: UltrastarTxt): +def pitch_audio(is_audio: bool, transcribed_data: list[TranscribedData], ultrastar_class: UltrastarTxtValue): """Pitch audio""" # todo: chunk pitching as option? # midi_notes = pitch_each_chunk_with_crepe(chunk_folder_name) @@ -716,7 +716,7 @@ def create_audio_chunks( is_audio: bool, transcribed_data: list[TranscribedData], ultrastar_audio_input_path: str, - ultrastar_class: UltrastarTxt + ultrastar_class: UltrastarTxtValue ) -> None: """Create audio chunks""" audio_chunks_path = os.path.join( diff --git a/modules/Audio/vocal_chunks.py b/modules/Audio/vocal_chunks.py index 72d6f04..b5301ec 100644 --- a/modules/Audio/vocal_chunks.py +++ b/modules/Audio/vocal_chunks.py @@ -10,7 +10,7 @@ from modules.Ultrastar.ultrastar_converter import ( get_end_time_from_ultrastar, get_start_time_from_ultrastar, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue class AudioManipulation: @@ -41,7 +41,7 @@ def export_chunks_from_transcribed_data( def export_chunks_from_ultrastar_data( - audio_filename: str, ultrastar_data: UltrastarTxt, folder_name: str + audio_filename: str, ultrastar_data: UltrastarTxtValue, folder_name: str ) -> None: """Export ultrastar data as vocal chunks wav files""" print(f"{ULTRASINGER_HEAD} Export Ultrastar data as vocal chunks wav files") diff --git a/modules/Midi/midi_creator.py b/modules/Midi/midi_creator.py index ee4aa75..9c2111e 100644 --- a/modules/Midi/midi_creator.py +++ b/modules/Midi/midi_creator.py @@ -17,11 +17,11 @@ from modules.console_colors import ( ULTRASINGER_HEAD, red_highlighted, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue from modules.Pitcher.pitched_data import PitchedData -def convert_ultrastar_to_midi_instrument(ultrastar_class: UltrastarTxt) -> object: +def convert_ultrastar_to_midi_instrument(ultrastar_class: UltrastarTxtValue) -> object: """Converts an Ultrastar data to a midi instrument""" print(f"{ULTRASINGER_HEAD} Creating midi instrument from Ultrastar txt") diff --git a/modules/Ultrastar/ultrastar_converter.py b/modules/Ultrastar/ultrastar_converter.py index ce15c93..66e5977 100644 --- a/modules/Ultrastar/ultrastar_converter.py +++ b/modules/Ultrastar/ultrastar_converter.py @@ -1,6 +1,6 @@ """Ultrastar Converter""" -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue def real_bpm_to_ultrastar_bpm(real_bpm: float) -> float: """Converts real BPM to UltraStar BPM""" @@ -48,7 +48,7 @@ def ultrastar_note_to_midi_note(ultrastar_note: int) -> int: return midi_note -def get_start_time_from_ultrastar(ultrastar_class: UltrastarTxt, pos: int) -> float: +def get_start_time_from_ultrastar(ultrastar_class: UltrastarTxtValue, pos: int) -> float: """Calculates the start time from the Ultrastar txt""" gap = int(ultrastar_class.gap) / 1000 @@ -61,7 +61,7 @@ def get_start_time_from_ultrastar(ultrastar_class: UltrastarTxt, pos: int) -> fl return start_time -def get_end_time_from_ultrastar(ultrastar_class: UltrastarTxt, pos: int) -> float: +def get_end_time_from_ultrastar(ultrastar_class: UltrastarTxtValue, pos: int) -> float: """Calculates the end time from the Ultrastar txt""" gap = int(ultrastar_class.gap) / 1000 diff --git a/modules/Ultrastar/ultrastar_parser.py b/modules/Ultrastar/ultrastar_parser.py index 0af6ec2..9bba162 100644 --- a/modules/Ultrastar/ultrastar_parser.py +++ b/modules/Ultrastar/ultrastar_parser.py @@ -5,34 +5,38 @@ from modules.Ultrastar.ultrastar_converter import ( get_end_time_from_ultrastar, get_start_time_from_ultrastar, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, FILE_ENCODING - -def parse_ultrastar_txt(input_file: str) -> UltrastarTxt: +def parse_ultrastar_txt(input_file: str) -> UltrastarTxtValue: """Parse ultrastar txt file to UltrastarTxt class""" print(f"{ULTRASINGER_HEAD} Parse ultrastar txt -> {input_file}") - with open(input_file, "r", encoding="utf-8") as file: + with open(input_file, "r", encoding=FILE_ENCODING) as file: txt = file.readlines() - ultrastar_class = UltrastarTxt() + ultrastar_class = UltrastarTxtValue() count = 0 # Strips the newline character for line in txt: count += 1 if line.startswith("#"): - if line.startswith("#ARTIST"): + if line.startswith(f"#{UltrastarTxtTag.ARTIST}"): ultrastar_class.artist = line.split(":")[1].replace("\n", "") - elif line.startswith("#TITLE"): + elif line.startswith(f"#{UltrastarTxtTag.TITLE}"): ultrastar_class.title = line.split(":")[1].replace("\n", "") - elif line.startswith("#MP3"): + elif line.startswith(f"#{UltrastarTxtTag.MP3}"): ultrastar_class.mp3 = line.split(":")[1].replace("\n", "") - elif line.startswith("#GAP"): + elif line.startswith(f"#{UltrastarTxtTag.GAP}"): ultrastar_class.gap = line.split(":")[1].replace("\n", "") - elif line.startswith("#BPM"): + elif line.startswith(f"#{UltrastarTxtTag.BPM}"): ultrastar_class.bpm = line.split(":")[1].replace("\n", "") - elif line.startswith(("F ", ": ", "* ", "R ", "G ")): + elif line.startswith(( + f"{UltrastarTxtNoteTypeTag.FREESTYLE} ", + f"{UltrastarTxtNoteTypeTag.NORMAL} ", + f"{UltrastarTxtNoteTypeTag.GOLDEN} ", + f"{UltrastarTxtNoteTypeTag.RAP} ", + f"{UltrastarTxtNoteTypeTag.RAP_GOLDEN} ")): parts = line.split() # [0] F : * R G # [1] start beat diff --git a/modules/Ultrastar/ultrastar_score_calculator.py b/modules/Ultrastar/ultrastar_score_calculator.py index b789dd0..78da5e9 100644 --- a/modules/Ultrastar/ultrastar_score_calculator.py +++ b/modules/Ultrastar/ultrastar_score_calculator.py @@ -16,7 +16,7 @@ from modules.Ultrastar.ultrastar_converter import ( get_start_time_from_ultrastar, ultrastar_note_to_midi_note, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue from modules.Pitcher.pitched_data import PitchedData MAX_SONG_SCORE = 10000 @@ -84,7 +84,7 @@ def print_score(score: Score) -> None: ) -def calculate_score(pitched_data: PitchedData, ultrastar_class: UltrastarTxt) -> (Score, Score): +def calculate_score(pitched_data: PitchedData, ultrastar_class: UltrastarTxtValue) -> (Score, Score): """Calculate score.""" print(ULTRASINGER_HEAD + " Calculating Ultrastar Points") diff --git a/modules/Ultrastar/ultrastar_txt.py b/modules/Ultrastar/ultrastar_txt.py index f29b64e..0c8bd2f 100644 --- a/modules/Ultrastar/ultrastar_txt.py +++ b/modules/Ultrastar/ultrastar_txt.py @@ -1,8 +1,61 @@ -"""Docstring""" +"""Ultrastar TXT""" +from enum import Enum + +FILE_ENCODING = "utf-8" -class UltrastarTxt: - """Docstring""" +class UltrastarTxtTag(str, Enum): + """Tags for Ultrastar TXT files.""" + + ARTIST = 'ARTIST' + TITLE = 'TITLE' + MP3 = 'MP3' + GAP = 'GAP' + BPM = 'BPM' + LANGUAGE = 'LANGUAGE' + COVER = 'COVER' # Path to cover. Should end with `*[CO].jpg` + CREATOR = 'CREATOR' + COMMENT = 'COMMENT' + VIDEO = 'VIDEO' + FILE_END = 'E' + LINEBREAK = '-' + + # Only used in UltraStar World Party + FIXER = 'FIXER' + + # Unused + BACKGROUND = 'BACKGROUND' # Path to background. Is shown when there is no video. Should end with `*[BG].jpg` + VIDEOGAP = 'VIDEOGAP' + GENRE = 'GENRE' + EDITION = 'EDITION' + YEAR = 'YEAR' + START = 'START' + END = 'END' + RESOLUTION = 'RESOLUTION' # Changes the grid resolution of the editor. Only for the editor and nothing for singing. + NOTESGAP = 'NOTESGAP' + RELATIVE = 'RELATIVE' + ENCODING = 'ENCODING' + PREVIEWSTART = 'PREVIEWSTART' + MEDLEYSTARTBEAT = 'MEDLEYSTARTBEAT' + MEDLEYENDBEAT = 'MEDLEYENDBEAT' + CALCMEDLEY = 'CALCMEDLEY' + DUETSINGERP1 = 'DUETSINGERP1' + DUETSINGERP2 = 'DUETSINGERP2' + P1 = 'P1' # Only for UltraStar Deluxe + P2 = 'P2' # Only for UltraStar Deluxe + + +class UltrastarTxtNoteTypeTag(str, Enum): + """Note types for Ultrastar TXT files.""" + NORMAL = ':' + RAP = 'R' + RAP_GOLDEN = 'G' + FREESTYLE = 'F' + GOLDEN = '*' + + +class UltrastarTxtValue: + """Vaules for Ultrastar TXT files.""" artist = "" title = "" @@ -13,7 +66,6 @@ class UltrastarTxt: language = None cover = None creator = "UltraSinger [GitHub]" - fixer = "YOUR NAME" # Only for UltraStar World Party comment = "UltraSinger [GitHub]" startBeat = [] startTimes = [] @@ -22,3 +74,6 @@ class UltrastarTxt: pitches = [] words = [] noteType = [] # F, R, G, *, : + + # Only used in UltraStar World Party + fixer = "YOUR NAME" diff --git a/modules/Ultrastar/ultrastar_writer.py b/modules/Ultrastar/ultrastar_writer.py index ba197f1..6767c7e 100644 --- a/modules/Ultrastar/ultrastar_writer.py +++ b/modules/Ultrastar/ultrastar_writer.py @@ -9,7 +9,7 @@ from modules.Ultrastar.ultrastar_converter import ( real_bpm_to_ultrastar_bpm, second_to_beat, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxt +from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, FILE_ENCODING from modules.Speech_Recognition.TranscribedData import TranscribedData from modules.Ultrastar.ultrastar_score_calculator import Score @@ -38,7 +38,7 @@ def create_ultrastar_txt_from_automation( transcribed_data: list[TranscribedData], note_numbers: list[int], ultrastar_file_output: str, - ultrastar_class: UltrastarTxt, + ultrastar_class: UltrastarTxtValue, bpm=120, ) -> None: """Creates an Ultrastar txt file from the automation data""" @@ -51,24 +51,24 @@ def create_ultrastar_txt_from_automation( multiplication = get_multiplier(real_bpm) ultrastar_bpm = real_bpm * get_multiplier(real_bpm) - with open(ultrastar_file_output, "w", encoding="utf-8") as file: + with open(ultrastar_file_output, "w", encoding=FILE_ENCODING) as file: gap = transcribed_data[0].start - file.write(f"#ARTIST:{ultrastar_class.artist}\n") - file.write(f"#TITLE:{ultrastar_class.title}\n") - file.write(f"#CREATOR:{ultrastar_class.creator}\n") - file.write(f"#FIXER:{ultrastar_class.fixer}\n") + file.write(f"#{UltrastarTxtTag.ARTIST}:{ultrastar_class.artist}\n") + file.write(f"#{UltrastarTxtTag.TITLE}:{ultrastar_class.title}\n") + file.write(f"#{UltrastarTxtTag.CREATOR}:{ultrastar_class.creator}\n") + file.write(f"#{UltrastarTxtTag.FIXER}:{ultrastar_class.fixer}\n") if ultrastar_class.language is not None: file.write( - f"#LANGUAGE:{get_language_name(ultrastar_class.language)}\n" + f"#{UltrastarTxtTag.LANGUAGE}:{get_language_name(ultrastar_class.language)}\n" ) if ultrastar_class.cover is not None: - file.write(f"#COVER:{ultrastar_class.cover}\n") - file.write(f"#MP3:{ultrastar_class.mp3}\n") - file.write(f"#VIDEO:{ultrastar_class.video}\n") - file.write(f"#BPM:{round(ultrastar_bpm, 2)}\n") # not the real BPM! - file.write(f"#GAP:{int(gap * 1000)}\n") - file.write(f"#COMMENT:{ultrastar_class.comment}\n") + file.write(f"#{UltrastarTxtTag.COVER}:{ultrastar_class.cover}\n") + file.write(f"#{UltrastarTxtTag.MP3}:{ultrastar_class.mp3}\n") + file.write(f"#{UltrastarTxtTag.VIDEO}:{ultrastar_class.video}\n") + file.write(f"#{UltrastarTxtTag.BPM}:{round(ultrastar_bpm, 2)}\n") # not the real BPM! + file.write(f"#{UltrastarTxtTag.GAP}:{int(gap * 1000)}\n") + file.write(f"#{UltrastarTxtTag.COMMENT}:{ultrastar_class.comment}\n") # Write the singing part previous_end_beat = 0 @@ -90,7 +90,7 @@ def create_ultrastar_txt_from_automation( # 'n2' duration at real beat # 'n3' pitch where 0 == C4 # 'w' lyric - file.write(": ") + file.write(f"{UltrastarTxtNoteTypeTag.NORMAL} ") file.write(str(start_beat) + " ") file.write(str(duration) + " ") file.write(str(note_numbers[i]) + " ") @@ -109,14 +109,14 @@ def create_ultrastar_txt_from_automation( # - 10 # '-' end of current sing part # 'n1' show next at time in real beat - file.write("- ") + file.write(f"{UltrastarTxtTag.LINEBREAK} ") show_next = ( second_to_beat(data.end - gap, bpm) * multiplication ) file.write(str(round(show_next))) file.write("\n") - file.write("E") + file.write(f"{UltrastarTxtTag.FILE_END}") def create_repitched_txt_from_ultrastar_data( @@ -129,14 +129,14 @@ def create_repitched_txt_from_ultrastar_data( ) # todo: to reader - with open(input_file, "r", encoding="utf-8") as file: + with open(input_file, "r", encoding=FILE_ENCODING) as file: txt = file.readlines() i = 0 # todo: just add '_repitched' to input_file - with open(output_repitched_ultrastar, "w", encoding="utf-8") as file: + with open(output_repitched_ultrastar, "w", encoding=FILE_ENCODING) as file: for line in txt: - if line.startswith(":"): + if line.startswith(f"#{UltrastarTxtNoteTypeTag.NORMAL} "): parts = re.findall(r"\S+|\s+", line) # between are whitespaces # [0] : @@ -154,27 +154,32 @@ def create_repitched_txt_from_ultrastar_data( def add_score_to_ultrastar_txt(ultrastar_file_output: str, score: Score) -> None: """Adds the score to the ultrastar txt file""" - with open(ultrastar_file_output, "r", encoding="utf-8") as file: + with open(ultrastar_file_output, "r", encoding=FILE_ENCODING) as file: text = file.read() text = text.split("\n") for i, line in enumerate(text): - if line.startswith("#COMMENT:"): + if line.startswith(f"#{UltrastarTxtTag.COMMENT}:"): text[ i ] = f"{line} | Score: total: {score.score}, notes: {score.notes} line: {score.line_bonus}, golden: {score.golden}" break - if line.startswith(("F ", ": ", "* ", "R ", "G ")): + if line.startswith(( + f"{UltrastarTxtNoteTypeTag.FREESTYLE} ", + f"{UltrastarTxtNoteTypeTag.NORMAL} ", + f"{UltrastarTxtNoteTypeTag.GOLDEN} ", + f"{UltrastarTxtNoteTypeTag.RAP} ", + f"{UltrastarTxtNoteTypeTag.RAP_GOLDEN} ")): text.insert( i, - f"#COMMENT: UltraSinger [GitHub] | Score: total: {score.score}, notes: {score.notes} line: {score.line_bonus}, golden: {score.golden}", + f"#{UltrastarTxtTag.COMMENT}: UltraSinger [GitHub] | Score: total: {score.score}, notes: {score.notes} line: {score.line_bonus}, golden: {score.golden}", ) break text = "\n".join(text) - with open(ultrastar_file_output, "w", encoding="utf-8") as file: + with open(ultrastar_file_output, "w", encoding=FILE_ENCODING) as file: file.write(text) From f8901c55c5970d02a41d131426a590f42a6cdf01 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 14:08:33 +0200 Subject: [PATCH 28/40] - move soruce to src directory --- .../UltraStar/test_ultrastar_converter.py | 2 +- Settings.py => src/Settings.py | 0 UltraSinger.py => src/UltraSinger.py | 48 ++++++++----------- .../modules}/Audio/convert_audio.py | 2 +- {modules => src/modules}/Audio/denoise.py | 2 +- {modules => src/modules}/Audio/separation.py | 4 +- .../modules}/Audio/silence_processing.py | 4 +- .../modules}/Audio/vocal_chunks.py | 8 ++-- {modules => src/modules}/Audio/youtube.py | 2 +- .../DeviceDetection/device_detection.py | 2 +- {modules => src/modules}/Midi/midi_creator.py | 10 ++-- .../modules}/Pitcher/pitched_data.py | 0 {modules => src/modules}/Pitcher/pitcher.py | 4 +- .../Speech_Recognition/TranscribedData.py | 0 .../modules}/Speech_Recognition/Vosk.py | 4 +- .../modules}/Speech_Recognition/Whisper.py | 4 +- .../Speech_Recognition/hyphenation.py | 2 +- .../Speech_Recognition/speech_recognition.py | 2 +- .../modules}/Ultrastar/ultrastar_converter.py | 2 +- .../modules}/Ultrastar/ultrastar_parser.py | 6 +-- .../Ultrastar/ultrastar_score_calculator.py | 10 ++-- .../modules}/Ultrastar/ultrastar_txt.py | 0 .../modules}/Ultrastar/ultrastar_writer.py | 10 ++-- {modules => src/modules}/console_colors.py | 0 {modules => src/modules}/csv_handler.py | 4 +- {modules => src/modules}/os_helper.py | 2 +- 26 files changed, 64 insertions(+), 70 deletions(-) rename Settings.py => src/Settings.py (100%) rename UltraSinger.py => src/UltraSinger.py (95%) rename {modules => src/modules}/Audio/convert_audio.py (93%) rename {modules => src/modules}/Audio/denoise.py (92%) rename {modules => src/modules}/Audio/separation.py (86%) rename {modules => src/modules}/Audio/silence_processing.py (92%) rename {modules => src/modules}/Audio/vocal_chunks.py (92%) rename {modules => src/modules}/Audio/youtube.py (97%) rename {modules => src/modules}/DeviceDetection/device_detection.py (86%) rename {modules => src/modules}/Midi/midi_creator.py (92%) rename {modules => src/modules}/Pitcher/pitched_data.py (100%) rename {modules => src/modules}/Pitcher/pitcher.py (94%) rename {modules => src/modules}/Speech_Recognition/TranscribedData.py (100%) rename {modules => src/modules}/Speech_Recognition/Vosk.py (93%) rename {modules => src/modules}/Speech_Recognition/Whisper.py (94%) rename {modules => src/modules}/Speech_Recognition/hyphenation.py (96%) rename {modules => src/modules}/Speech_Recognition/speech_recognition.py (98%) rename {modules => src/modules}/Ultrastar/ultrastar_converter.py (97%) rename {modules => src/modules}/Ultrastar/ultrastar_parser.py (91%) rename {modules => src/modules}/Ultrastar/ultrastar_score_calculator.py (93%) rename {modules => src/modules}/Ultrastar/ultrastar_txt.py (100%) rename {modules => src/modules}/Ultrastar/ultrastar_writer.py (94%) rename {modules => src/modules}/console_colors.py (100%) rename {modules => src/modules}/csv_handler.py (91%) rename {modules => src/modules}/os_helper.py (94%) diff --git a/pytest/modules/UltraStar/test_ultrastar_converter.py b/pytest/modules/UltraStar/test_ultrastar_converter.py index 9f5760d..9e72a4f 100644 --- a/pytest/modules/UltraStar/test_ultrastar_converter.py +++ b/pytest/modules/UltraStar/test_ultrastar_converter.py @@ -1,6 +1,6 @@ """Tests for ultrastar_converter.py""" -from modules.Ultrastar.ultrastar_converter import real_bpm_to_ultrastar_bpm +from src.modules.Ultrastar.ultrastar_converter import real_bpm_to_ultrastar_bpm def test_real_bpm_to_ultrastar_bpm(): diff --git a/Settings.py b/src/Settings.py similarity index 100% rename from Settings.py rename to src/Settings.py diff --git a/UltraSinger.py b/src/UltraSinger.py similarity index 95% rename from UltraSinger.py rename to src/UltraSinger.py index 773da64..1be0358 100644 --- a/UltraSinger.py +++ b/src/UltraSinger.py @@ -5,60 +5,54 @@ import getopt import os import sys from time import sleep -from typing import Tuple, Any import Levenshtein import librosa from matplotlib import pyplot as plt from tqdm import tqdm -from modules import os_helper -from modules.Audio.denoise import ffmpeg_reduce_noise -from modules.Audio.separation import separate_audio -from modules.Audio.vocal_chunks import ( +from src.modules import os_helper +from src.modules.Audio.denoise import ffmpeg_reduce_noise +from src.modules.Audio.separation import separate_audio +from src.modules.Audio.vocal_chunks import ( export_chunks_from_transcribed_data, export_chunks_from_ultrastar_data, ) -from modules.Audio.silence_processing import remove_silence_from_transcribtion_data -from modules.csv_handler import export_transcribed_data_to_csv -from modules.Audio.convert_audio import convert_audio_to_mono_wav, convert_wav_to_mp3 -from modules.Audio.youtube import ( +from src.modules.Audio.silence_processing import remove_silence_from_transcribtion_data +from src.modules.csv_handler import export_transcribed_data_to_csv +from src.modules.Audio.convert_audio import convert_audio_to_mono_wav, convert_wav_to_mp3 +from src.modules.Audio.youtube import ( download_youtube_audio, download_youtube_thumbnail, download_youtube_video, get_youtube_title, ) -from modules.DeviceDetection.device_detection import get_available_device -from modules.console_colors import ( +from src.modules.DeviceDetection.device_detection import get_available_device +from src.modules.console_colors import ( ULTRASINGER_HEAD, blue_highlighted, gold_highlighted, light_blue_highlighted, red_highlighted, ) -from modules.Midi import midi_creator -from modules.Midi.midi_creator import ( +from src.modules.Midi import midi_creator +from src.modules.Midi.midi_creator import ( convert_frequencies_to_notes, create_midi_notes_from_pitched_data, most_frequent, ) -from modules.Pitcher.pitcher import ( +from src.modules.Pitcher.pitcher import ( get_frequency_with_high_confidence, get_pitch_with_crepe_file, ) -from modules.Pitcher.pitched_data import PitchedData -from modules.Speech_Recognition.hyphenation import hyphenation, language_check -from modules.Speech_Recognition.Vosk import transcribe_with_vosk -from modules.Speech_Recognition.Whisper import transcribe_with_whisper -from modules.Ultrastar import ( - ultrastar_converter, - ultrastar_parser, - ultrastar_score_calculator, - ultrastar_writer, -) -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue +from src.modules.Pitcher.pitched_data import PitchedData +from src.modules.Speech_Recognition.hyphenation import hyphenation, language_check +from src.modules.Speech_Recognition.Vosk import transcribe_with_vosk +from src.modules.Speech_Recognition.Whisper import transcribe_with_whisper +from src.modules.Ultrastar import ultrastar_score_calculator, ultrastar_writer, ultrastar_converter, ultrastar_parser +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue from Settings import Settings -from modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.Speech_Recognition.TranscribedData import TranscribedData settings = Settings() @@ -792,7 +786,7 @@ def init_settings(argv: list[str]) -> None: dirname = os.getcwd() else: dirname = os.path.dirname(settings.input_file_path) - settings.output_file_path = os.path.join(dirname, "output") + settings.output_file_path = os.path.join(dirname, "../output") settings.device = get_available_device() diff --git a/modules/Audio/convert_audio.py b/src/modules/Audio/convert_audio.py similarity index 93% rename from modules/Audio/convert_audio.py rename to src/modules/Audio/convert_audio.py index 6642706..f865f00 100644 --- a/modules/Audio/convert_audio.py +++ b/src/modules/Audio/convert_audio.py @@ -2,7 +2,7 @@ from pydub import AudioSegment -from modules.console_colors import ULTRASINGER_HEAD +from src.modules.console_colors import ULTRASINGER_HEAD def convert_audio_to_mono_wav(input_file: str, output_file: str) -> None: diff --git a/modules/Audio/denoise.py b/src/modules/Audio/denoise.py similarity index 92% rename from modules/Audio/denoise.py rename to src/modules/Audio/denoise.py index 5987739..1801dbe 100644 --- a/modules/Audio/denoise.py +++ b/src/modules/Audio/denoise.py @@ -2,7 +2,7 @@ import ffmpeg -from modules.console_colors import ULTRASINGER_HEAD, blue_highlighted +from src.modules.console_colors import ULTRASINGER_HEAD, blue_highlighted def ffmpeg_reduce_noise(input_file_path: str, output_file: str) -> None: diff --git a/modules/Audio/separation.py b/src/modules/Audio/separation.py similarity index 86% rename from modules/Audio/separation.py rename to src/modules/Audio/separation.py index d34241e..bcb2c26 100644 --- a/modules/Audio/separation.py +++ b/src/modules/Audio/separation.py @@ -2,12 +2,12 @@ import subprocess -from modules.console_colors import ( +from src.modules.console_colors import ( ULTRASINGER_HEAD, blue_highlighted, red_highlighted, ) -from modules.os_helper import current_executor_path, move, path_join +from src.modules.os_helper import current_executor_path, move, path_join def separate_audio(input_file_path: str, output_file: str, device="cpu") -> None: diff --git a/modules/Audio/silence_processing.py b/src/modules/Audio/silence_processing.py similarity index 92% rename from modules/Audio/silence_processing.py rename to src/modules/Audio/silence_processing.py index e139547..9e824a6 100644 --- a/modules/Audio/silence_processing.py +++ b/src/modules/Audio/silence_processing.py @@ -2,8 +2,8 @@ import librosa -from modules.console_colors import ULTRASINGER_HEAD -from modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.console_colors import ULTRASINGER_HEAD +from src.modules.Speech_Recognition.TranscribedData import TranscribedData def remove_silence_from_transcribtion_data(audio_path: str, transcribed_data: list[TranscribedData]) -> list[TranscribedData]: diff --git a/modules/Audio/vocal_chunks.py b/src/modules/Audio/vocal_chunks.py similarity index 92% rename from modules/Audio/vocal_chunks.py rename to src/modules/Audio/vocal_chunks.py index b5301ec..88aed81 100644 --- a/modules/Audio/vocal_chunks.py +++ b/src/modules/Audio/vocal_chunks.py @@ -4,13 +4,13 @@ import os import re import wave -from modules.console_colors import ULTRASINGER_HEAD -from modules.os_helper import create_folder -from modules.Ultrastar.ultrastar_converter import ( +from src.modules.console_colors import ULTRASINGER_HEAD +from src.modules.os_helper import create_folder +from src.modules.Ultrastar.ultrastar_converter import ( get_end_time_from_ultrastar, get_start_time_from_ultrastar, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue class AudioManipulation: diff --git a/modules/Audio/youtube.py b/src/modules/Audio/youtube.py similarity index 97% rename from modules/Audio/youtube.py rename to src/modules/Audio/youtube.py index 6ea553e..bcda43c 100644 --- a/modules/Audio/youtube.py +++ b/src/modules/Audio/youtube.py @@ -6,7 +6,7 @@ import os import yt_dlp from PIL import Image -from modules.console_colors import ULTRASINGER_HEAD +from src.modules.console_colors import ULTRASINGER_HEAD def get_youtube_title(url: str) -> str: diff --git a/modules/DeviceDetection/device_detection.py b/src/modules/DeviceDetection/device_detection.py similarity index 86% rename from modules/DeviceDetection/device_detection.py rename to src/modules/DeviceDetection/device_detection.py index 5912438..8545711 100644 --- a/modules/DeviceDetection/device_detection.py +++ b/src/modules/DeviceDetection/device_detection.py @@ -2,7 +2,7 @@ import torch -from modules.console_colors import ULTRASINGER_HEAD, red_highlighted +from src.modules.console_colors import ULTRASINGER_HEAD, red_highlighted def get_available_device() -> str: diff --git a/modules/Midi/midi_creator.py b/src/modules/Midi/midi_creator.py similarity index 92% rename from modules/Midi/midi_creator.py rename to src/modules/Midi/midi_creator.py index 9c2111e..1d09e13 100644 --- a/modules/Midi/midi_creator.py +++ b/src/modules/Midi/midi_creator.py @@ -7,18 +7,18 @@ import librosa import numpy as np import pretty_midi -from modules.Pitcher.pitcher import get_frequency_with_high_confidence -from modules.Ultrastar.ultrastar_converter import ( +from src.modules.Pitcher.pitcher import get_frequency_with_high_confidence +from src.modules.Ultrastar.ultrastar_converter import ( get_end_time_from_ultrastar, get_start_time_from_ultrastar, ultrastar_note_to_midi_note, ) -from modules.console_colors import ( +from src.modules.console_colors import ( ULTRASINGER_HEAD, red_highlighted, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue -from modules.Pitcher.pitched_data import PitchedData +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue +from src.modules.Pitcher.pitched_data import PitchedData def convert_ultrastar_to_midi_instrument(ultrastar_class: UltrastarTxtValue) -> object: diff --git a/modules/Pitcher/pitched_data.py b/src/modules/Pitcher/pitched_data.py similarity index 100% rename from modules/Pitcher/pitched_data.py rename to src/modules/Pitcher/pitched_data.py diff --git a/modules/Pitcher/pitcher.py b/src/modules/Pitcher/pitcher.py similarity index 94% rename from modules/Pitcher/pitcher.py rename to src/modules/Pitcher/pitcher.py index 2d17c67..ef614d7 100644 --- a/modules/Pitcher/pitcher.py +++ b/src/modules/Pitcher/pitcher.py @@ -3,12 +3,12 @@ import crepe from scipy.io import wavfile -from modules.console_colors import ( +from src.modules.console_colors import ( ULTRASINGER_HEAD, blue_highlighted, red_highlighted, ) -from modules.Pitcher.pitched_data import PitchedData +from src.modules.Pitcher.pitched_data import PitchedData def get_pitch_with_crepe_file(filename: str, step_size: int, model_capacity: str) -> PitchedData: diff --git a/modules/Speech_Recognition/TranscribedData.py b/src/modules/Speech_Recognition/TranscribedData.py similarity index 100% rename from modules/Speech_Recognition/TranscribedData.py rename to src/modules/Speech_Recognition/TranscribedData.py diff --git a/modules/Speech_Recognition/Vosk.py b/src/modules/Speech_Recognition/Vosk.py similarity index 93% rename from modules/Speech_Recognition/Vosk.py rename to src/modules/Speech_Recognition/Vosk.py index 08d77e5..dfdf1d2 100644 --- a/modules/Speech_Recognition/Vosk.py +++ b/src/modules/Speech_Recognition/Vosk.py @@ -5,8 +5,8 @@ import wave from vosk import KaldiRecognizer, Model -from modules.console_colors import ULTRASINGER_HEAD -from modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.console_colors import ULTRASINGER_HEAD +from src.modules.Speech_Recognition.TranscribedData import TranscribedData # todo: Rename to Transcoder? diff --git a/modules/Speech_Recognition/Whisper.py b/src/modules/Speech_Recognition/Whisper.py similarity index 94% rename from modules/Speech_Recognition/Whisper.py rename to src/modules/Speech_Recognition/Whisper.py index e452673..e553a64 100644 --- a/modules/Speech_Recognition/Whisper.py +++ b/src/modules/Speech_Recognition/Whisper.py @@ -2,12 +2,12 @@ import whisperx -from modules.console_colors import ( +from src.modules.console_colors import ( ULTRASINGER_HEAD, blue_highlighted, red_highlighted, ) -from modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.Speech_Recognition.TranscribedData import TranscribedData def transcribe_with_whisper(audio_path: str, model: str, device="cpu") -> (list[TranscribedData], str): diff --git a/modules/Speech_Recognition/hyphenation.py b/src/modules/Speech_Recognition/hyphenation.py similarity index 96% rename from modules/Speech_Recognition/hyphenation.py rename to src/modules/Speech_Recognition/hyphenation.py index a04f214..4d65b9c 100644 --- a/modules/Speech_Recognition/hyphenation.py +++ b/src/modules/Speech_Recognition/hyphenation.py @@ -4,7 +4,7 @@ import string from hyphen import Hyphenator, dictools -from modules.console_colors import ( +from src.modules.console_colors import ( ULTRASINGER_HEAD, blue_highlighted, ) diff --git a/modules/Speech_Recognition/speech_recognition.py b/src/modules/Speech_Recognition/speech_recognition.py similarity index 98% rename from modules/Speech_Recognition/speech_recognition.py rename to src/modules/Speech_Recognition/speech_recognition.py index 08d829d..6a343bf 100644 --- a/modules/Speech_Recognition/speech_recognition.py +++ b/src/modules/Speech_Recognition/speech_recognition.py @@ -6,7 +6,7 @@ import speech_recognition as sr from pydub import AudioSegment from pydub.silence import split_on_silence -from modules.console_colors import ULTRASINGER_HEAD +from src.modules.console_colors import ULTRASINGER_HEAD # todo: Code from here: https://www.thepythoncode.com/article/using-speech-recognition-to-convert-speech-to-text-python diff --git a/modules/Ultrastar/ultrastar_converter.py b/src/modules/Ultrastar/ultrastar_converter.py similarity index 97% rename from modules/Ultrastar/ultrastar_converter.py rename to src/modules/Ultrastar/ultrastar_converter.py index 66e5977..d07b8f2 100644 --- a/modules/Ultrastar/ultrastar_converter.py +++ b/src/modules/Ultrastar/ultrastar_converter.py @@ -1,6 +1,6 @@ """Ultrastar Converter""" -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue def real_bpm_to_ultrastar_bpm(real_bpm: float) -> float: """Converts real BPM to UltraStar BPM""" diff --git a/modules/Ultrastar/ultrastar_parser.py b/src/modules/Ultrastar/ultrastar_parser.py similarity index 91% rename from modules/Ultrastar/ultrastar_parser.py rename to src/modules/Ultrastar/ultrastar_parser.py index 9bba162..12cef3c 100644 --- a/modules/Ultrastar/ultrastar_parser.py +++ b/src/modules/Ultrastar/ultrastar_parser.py @@ -1,11 +1,11 @@ """Ultrastar txt parser""" -from modules.console_colors import ULTRASINGER_HEAD -from modules.Ultrastar.ultrastar_converter import ( +from src.modules.console_colors import ULTRASINGER_HEAD +from src.modules.Ultrastar.ultrastar_converter import ( get_end_time_from_ultrastar, get_start_time_from_ultrastar, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, FILE_ENCODING +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, FILE_ENCODING def parse_ultrastar_txt(input_file: str) -> UltrastarTxtValue: """Parse ultrastar txt file to UltrastarTxt class""" diff --git a/modules/Ultrastar/ultrastar_score_calculator.py b/src/modules/Ultrastar/ultrastar_score_calculator.py similarity index 93% rename from modules/Ultrastar/ultrastar_score_calculator.py rename to src/modules/Ultrastar/ultrastar_score_calculator.py index 78da5e9..588abd8 100644 --- a/modules/Ultrastar/ultrastar_score_calculator.py +++ b/src/modules/Ultrastar/ultrastar_score_calculator.py @@ -2,7 +2,7 @@ import librosa -from modules.console_colors import ( +from src.modules.console_colors import ( ULTRASINGER_HEAD, blue_highlighted, cyan_highlighted, @@ -10,14 +10,14 @@ from modules.console_colors import ( light_blue_highlighted, underlined, ) -from modules.Midi.midi_creator import create_midi_note_from_pitched_data -from modules.Ultrastar.ultrastar_converter import ( +from src.modules.Midi.midi_creator import create_midi_note_from_pitched_data +from src.modules.Ultrastar.ultrastar_converter import ( get_end_time_from_ultrastar, get_start_time_from_ultrastar, ultrastar_note_to_midi_note, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue -from modules.Pitcher.pitched_data import PitchedData +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue +from src.modules.Pitcher.pitched_data import PitchedData MAX_SONG_SCORE = 10000 MAX_SONG_LINE_BONUS = 1000 diff --git a/modules/Ultrastar/ultrastar_txt.py b/src/modules/Ultrastar/ultrastar_txt.py similarity index 100% rename from modules/Ultrastar/ultrastar_txt.py rename to src/modules/Ultrastar/ultrastar_txt.py diff --git a/modules/Ultrastar/ultrastar_writer.py b/src/modules/Ultrastar/ultrastar_writer.py similarity index 94% rename from modules/Ultrastar/ultrastar_writer.py rename to src/modules/Ultrastar/ultrastar_writer.py index 6767c7e..3e8703f 100644 --- a/modules/Ultrastar/ultrastar_writer.py +++ b/src/modules/Ultrastar/ultrastar_writer.py @@ -4,14 +4,14 @@ import re import langcodes -from modules.console_colors import ULTRASINGER_HEAD -from modules.Ultrastar.ultrastar_converter import ( +from src.modules.console_colors import ULTRASINGER_HEAD +from src.modules.Ultrastar.ultrastar_converter import ( real_bpm_to_ultrastar_bpm, second_to_beat, ) -from modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, FILE_ENCODING -from modules.Speech_Recognition.TranscribedData import TranscribedData -from modules.Ultrastar.ultrastar_score_calculator import Score +from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue, UltrastarTxtTag, UltrastarTxtNoteTypeTag, FILE_ENCODING +from src.modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.Ultrastar.ultrastar_score_calculator import Score def get_multiplier(real_bpm: float) -> int: diff --git a/modules/console_colors.py b/src/modules/console_colors.py similarity index 100% rename from modules/console_colors.py rename to src/modules/console_colors.py diff --git a/modules/csv_handler.py b/src/modules/csv_handler.py similarity index 91% rename from modules/csv_handler.py rename to src/modules/csv_handler.py index 58cceeb..f2952fa 100644 --- a/modules/csv_handler.py +++ b/src/modules/csv_handler.py @@ -2,8 +2,8 @@ import csv -from modules.console_colors import ULTRASINGER_HEAD -from modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.console_colors import ULTRASINGER_HEAD +from src.modules.Speech_Recognition.TranscribedData import TranscribedData def export_transcribed_data_to_csv(transcribed_data: list[TranscribedData], filename: str) -> None: diff --git a/modules/os_helper.py b/src/modules/os_helper.py similarity index 94% rename from modules/os_helper.py rename to src/modules/os_helper.py index cc0a7c5..8cb65f6 100644 --- a/modules/os_helper.py +++ b/src/modules/os_helper.py @@ -3,7 +3,7 @@ import os import shutil -from modules.console_colors import ULTRASINGER_HEAD +from src.modules.console_colors import ULTRASINGER_HEAD def create_folder(folder_name: str) -> None: From 3eab89ef86074ef02c96439ce1fe4dc30bbafa31 Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 20:18:37 +0200 Subject: [PATCH 29/40] - try fix test path --- .github/workflows/pylint.yml | 6 +++++- .github/workflows/pytest.yml | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index f306e1a..bdaa706 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,6 +1,10 @@ name: Pylint -on: [push] +#on: [push] +on: + push: + paths: + - "none.txt" jobs: build: diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 9969ba5..e46d540 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -19,7 +19,10 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies - run: pip install -r requirements.txt + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -e . - name: Run pytest - run: pytest + run: python -m pytest --import-mode=append pytest/ From 687be927200d78dac1354855ec07a8036d2eb6ec Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 20:27:11 +0200 Subject: [PATCH 30/40] - try fix test --- .github/workflows/main.yml | 4 +++- .github/workflows/pytest.yml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d88209f..b4d73ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,9 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies - run: pip install -r requirements.txt + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt - name: Install gpu dependencies if: matrix.TARGET != 'macOS' diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index e46d540..23a583c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -22,7 +22,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install -e . + #pip install -e . - name: Run pytest run: python -m pytest --import-mode=append pytest/ From 75248b7c041ed6f1de4972e24fc4b4f8ab93090e Mon Sep 17 00:00:00 2001 From: Vadim Date: Thu, 8 Jun 2023 20:37:38 +0200 Subject: [PATCH 31/40] - Added test badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d0b08f9..2504a09 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![CodeFactor](https://www.codefactor.io/repository/github/rakuri255/ultrasinger/badge)](https://www.codefactor.io/repository/github/rakuri255/ultrasinger) [![Check Requirements](https://github.com/rakuri255/UltraSinger/actions/workflows/main.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/main.yml) +[![Pytest](https://github.com/rakuri255/UltraSinger/actions/workflows/pytest.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/pytest.yml) # UltraSinger From 6b3a243a434217799d9fab9ac1d603828ea4c7ad Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 10 Jun 2023 12:08:31 +0200 Subject: [PATCH 32/40] - Update Readme --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2504a09..34206de 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ This will help me alot to keep this project alive and improve it. For more information about Python environments look [here](https://code.visualstudio.com/docs/python/environments#_global-virtual-or-conda-environments). -As copy: +Installation As copy: ```commandline py -m venv .venv @@ -60,6 +60,27 @@ pip3 install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu11 ``` +Run UltraSinger: + +* Activate the environment with `.venv\Scripts\activate`. (You dont need this if you already activated it, or just installed with the step above) +* Navigate to src folder `cd src` +* Start UltraSinger `py UltraSinger.py` + +Start environment only once: + +```commandline +.venv\Scripts\activate +cd src + +``` + +Start UltraSinger: + +```commandline +py UltraSinger.py + +``` + ## How to use the App _Not all options working now!_ From 3915125adc780bc865b26c08807511748c8e252e Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 10 Jun 2023 13:29:06 +0200 Subject: [PATCH 33/40] - fix plot --- src/UltraSinger.py | 46 ++++----------------------------------------- src/modules/plot.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 42 deletions(-) create mode 100644 src/modules/plot.py diff --git a/src/UltraSinger.py b/src/UltraSinger.py index 1be0358..c8a59e0 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -8,7 +8,6 @@ from time import sleep import Levenshtein import librosa -from matplotlib import pyplot as plt from tqdm import tqdm from src.modules import os_helper @@ -53,25 +52,11 @@ from src.modules.Ultrastar import ultrastar_score_calculator, ultrastar_writer, from src.modules.Ultrastar.ultrastar_txt import UltrastarTxtValue from Settings import Settings from src.modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.plot import plot settings = Settings() -def get_confidence(pitched_data: PitchedData, threshold: float) -> tuple[list[float], list[float], list[float]]: - """Get high confidence data""" - # todo: replace get_frequency_with_high_conf from pitcher - conf_t = [] - conf_f = [] - conf_c = [] - for i in enumerate(pitched_data.times): - pos = i[0] - if pitched_data.confidence[i] > threshold: - conf_t.append(pitched_data.times[pos]) - conf_f.append(pitched_data.frequencies[pos]) - conf_c.append(pitched_data.confidence[pos]) - return conf_t, conf_f, conf_c - - def convert_midi_notes_to_ultrastar_notes(midi_notes: list[str]) -> list[int]: """Convert midi notes to ultrastar notes""" print(f"{ULTRASINGER_HEAD} Creating Ultrastar notes from midi data") @@ -223,29 +208,6 @@ def print_help() -> None: print(help_string) -def plot(input_file: str, transcribed_data: list[TranscribedData], midi_notes: list[str]) -> None: - """Plot transcribed data""" - pitched_data = get_pitch_with_crepe_file( - input_file, settings.crepe_step_size, settings.crepe_model_capacity - ) - conf_t, conf_f, conf_c = get_confidence(pitched_data, 0.4) - - plt.ylim(0, 600) - plt.xlim(0, 50) - plt.plot(conf_t, conf_f, linewidth=0.1) - plt.savefig(os.path.join("test", "crepe_0.4.png")) - - for i, data in enumerate(transcribed_data): - note_frequency = librosa.note_to_hz(midi_notes[i]) - plt.plot( - [data.start, data.end], - [note_frequency, note_frequency], - linewidth=1, - alpha=0.5, - ) - plt.savefig(os.path.join("test", "pit.png"), dpi=2000) - - def remove_unecessary_punctuations(transcribed_data: list[TranscribedData]) -> None: """Remove unecessary punctuations from transcribed data""" punctuation = ".," @@ -374,8 +336,8 @@ def run() -> None: ) # Create plot - if is_audio and settings.create_plot: - plot(ultrastar_audio_input_path, transcribed_data, midi_notes) + if settings.create_plot: + plot(pitched_data, transcribed_data, midi_notes, song_output) # Write Ultrastar txt if is_audio: @@ -786,7 +748,7 @@ def init_settings(argv: list[str]) -> None: dirname = os.getcwd() else: dirname = os.path.dirname(settings.input_file_path) - settings.output_file_path = os.path.join(dirname, "../output") + settings.output_file_path = os.path.join(dirname, "output") settings.device = get_available_device() diff --git a/src/modules/plot.py b/src/modules/plot.py new file mode 100644 index 0000000..69a7abb --- /dev/null +++ b/src/modules/plot.py @@ -0,0 +1,43 @@ +import os + +import librosa +from matplotlib import pyplot as plt + +from src.modules.Pitcher.pitched_data import PitchedData +from src.modules.Speech_Recognition.TranscribedData import TranscribedData + + +def plot(pitched_data: PitchedData, transcribed_data: list[TranscribedData], midi_notes: list[str], output_path: str) -> None: + """Plot transcribed data""" + + conf_t, conf_f, conf_c = get_confidence(pitched_data, 0.4) + + plt.ylim(0, 600) + plt.xlim(0, 50) + plt.plot(conf_t, conf_f, linewidth=0.1) + plt.savefig(os.path.join(output_path, "crepe_0.4.png")) + + for i, data in enumerate(transcribed_data): + note_frequency = librosa.note_to_hz(midi_notes[i]) + plt.plot( + [data.start, data.end], + [note_frequency, note_frequency], + linewidth=1, + alpha=0.5, + ) + plt.savefig(os.path.join(output_path, "pit.png"), dpi=2000) + + +def get_confidence(pitched_data: PitchedData, threshold: float) -> tuple[list[float], list[float], list[float]]: + """Get high confidence data""" + # todo: replace get_frequency_with_high_conf from pitcher + conf_t = [] + conf_f = [] + conf_c = [] + for i in enumerate(pitched_data.times): + pos = i[0] + if pitched_data.confidence[pos] > threshold: + conf_t.append(pitched_data.times[pos]) + conf_f.append(pitched_data.frequencies[pos]) + conf_c.append(pitched_data.confidence[pos]) + return conf_t, conf_f, conf_c From 376db08a5d6e26f745bf8f3ad2bf83b006f770d6 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 10 Jun 2023 20:53:40 +0200 Subject: [PATCH 34/40] - Enable plot in options - Optimize plot visualisation --- README.md | 9 +++++---- src/UltraSinger.py | 11 ++++++++--- src/modules/plot.py | 46 +++++++++++++++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 34206de..891603c 100644 --- a/README.md +++ b/README.md @@ -116,15 +116,16 @@ _Not all options working now!_ English-only model > tiny.en|base.en|small.en|medium.en --vosk Needs model + [pitcher] + # Default is crepe + --crepe tiny|small|medium|large|full >> ((default) is full) + [extra] --hyphenation True|False >> ((default) is True) --disable_separation True|False >> ((default) is False) --disable_karaoke True|False >> ((default) is False) --create_audio_chunks True|False >> ((default) is False) - - [pitcher] - # Default is crepe - --crepe tiny|small|medium|large|full >> ((default) is full) + --plot True|False >> ((default) is False) ``` For standard use, you only need to use [opt]. All other options are optional. diff --git a/src/UltraSinger.py b/src/UltraSinger.py index c8a59e0..52d862b 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -62,8 +62,9 @@ def convert_midi_notes_to_ultrastar_notes(midi_notes: list[str]) -> list[int]: print(f"{ULTRASINGER_HEAD} Creating Ultrastar notes from midi data") ultrastar_note_numbers = [] - for i, note in enumerate(midi_notes): - note_number_librosa = librosa.note_to_midi(note) + for i in enumerate(midi_notes): + pos = i[0] + note_number_librosa = librosa.note_to_midi(midi_notes[pos]) pitch = ultrastar_converter.midi_note_to_ultrastar_note( note_number_librosa ) @@ -640,7 +641,8 @@ def create_midi_file(is_audio: bool, real_bpm: float, song_output: str, ultrasta ) -def pitch_audio(is_audio: bool, transcribed_data: list[TranscribedData], ultrastar_class: UltrastarTxtValue): +def pitch_audio(is_audio: bool, transcribed_data: list[TranscribedData], ultrastar_class: UltrastarTxtValue) -> tuple[ + list[str], PitchedData, list[int]]: """Pitch audio""" # todo: chunk pitching as option? # midi_notes = pitch_each_chunk_with_crepe(chunk_folder_name) @@ -731,6 +733,8 @@ def init_settings(argv: list[str]) -> None: settings.vosk_model_path = arg elif opt in ("--crepe"): settings.crepe_model_capacity = arg + elif opt in ("--plot"): + settings.create_plot = arg elif opt in ("--hyphenation"): settings.hyphenation = arg elif opt in ("--disable_separation"): @@ -760,6 +764,7 @@ def arg_options(): "crepe=", "vosk=", "whisper=", + "plot=", "hyphenation=", "disable_separation=", "disable_karaoke=", diff --git a/src/modules/plot.py b/src/modules/plot.py index 69a7abb..a29ca4c 100644 --- a/src/modules/plot.py +++ b/src/modules/plot.py @@ -1,34 +1,56 @@ -import os +"""Plot transcribed data""" +import os import librosa from matplotlib import pyplot as plt - +from matplotlib.patches import Rectangle from src.modules.Pitcher.pitched_data import PitchedData from src.modules.Speech_Recognition.TranscribedData import TranscribedData +from src.modules.console_colors import ULTRASINGER_HEAD -def plot(pitched_data: PitchedData, transcribed_data: list[TranscribedData], midi_notes: list[str], output_path: str) -> None: +def get_frequency_range(midi_note: str) -> float: + midi = librosa.note_to_midi(midi_note) + frequency_range = librosa.midi_to_hz(midi + 1) - librosa.midi_to_hz(midi) + return frequency_range + + +def plot(pitched_data: PitchedData, + transcribed_data: list[TranscribedData], + midi_notes: list[str], + output_path: str + ) -> None: """Plot transcribed data""" + print(f"{ULTRASINGER_HEAD} Creating plot") + conf_t, conf_f, conf_c = get_confidence(pitched_data, 0.4) plt.ylim(0, 600) plt.xlim(0, 50) plt.plot(conf_t, conf_f, linewidth=0.1) - plt.savefig(os.path.join(output_path, "crepe_0.4.png")) for i, data in enumerate(transcribed_data): note_frequency = librosa.note_to_hz(midi_notes[i]) - plt.plot( - [data.start, data.end], - [note_frequency, note_frequency], - linewidth=1, - alpha=0.5, - ) - plt.savefig(os.path.join(output_path, "pit.png"), dpi=2000) + frequency_range = get_frequency_range(midi_notes[i]) + xy_start_pos = (data.start, note_frequency - frequency_range / 2) + width = data.end - data.start + height = frequency_range + rect = Rectangle( + xy_start_pos, + width, + height, + edgecolor='none', + facecolor='red', + alpha=0.5) + plt.gca().add_patch(rect) + plt.savefig(os.path.join(output_path, "plot.png"), dpi=3000) -def get_confidence(pitched_data: PitchedData, threshold: float) -> tuple[list[float], list[float], list[float]]: +def get_confidence( + pitched_data: PitchedData, + threshold: float +) -> tuple[list[float], list[float], list[float]]: """Get high confidence data""" # todo: replace get_frequency_with_high_conf from pitcher conf_t = [] From ab9d4338cc671cb90b51a5df0654d825fbff1733 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 10 Jun 2023 21:25:35 +0200 Subject: [PATCH 35/40] - Fix end time smaller than start time caused by hyphen enumaration issue --- src/UltraSinger.py | 7 ++++--- src/modules/Midi/midi_creator.py | 5 ----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/UltraSinger.py b/src/UltraSinger.py index 52d862b..38bbbfb 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -118,14 +118,15 @@ def add_hyphen_to_data(transcribed_data: list[TranscribedData], hyphen_words: li chunk_duration = chunk_duration / (len(hyphen_words[i])) next_start = data.start - for j, hyphens in enumerate(hyphen_words[i]): + for j in enumerate(hyphen_words[i]): + hyphenated_word_index = j[0] dup = copy.copy(data) dup.start = next_start next_start = data.end - chunk_duration * ( - len(hyphens) - 1 - j + len(hyphen_words[i]) - 1 - hyphenated_word_index ) dup.end = next_start - dup.word = hyphen_words[i][j] + dup.word = hyphen_words[i][hyphenated_word_index] dup.is_hyphen = True new_data.append(dup) diff --git a/src/modules/Midi/midi_creator.py b/src/modules/Midi/midi_creator.py index 1d09e13..33f397a 100644 --- a/src/modules/Midi/midi_creator.py +++ b/src/modules/Midi/midi_creator.py @@ -108,11 +108,6 @@ def create_midi_note_from_pitched_data(start_time: float, end_time: float, pitch start = find_nearest_index(pitched_data.times, start_time) end = find_nearest_index(pitched_data.times, end_time) - # fixme: why is end smaller as start? - if end < start: - print(f"{ULTRASINGER_HEAD} {red_highlighted('Error: end time is smaller as start time. The note is C0 now ...')}") - return "C0" - if start == end: freqs = [pitched_data.frequencies[start]] confs = [pitched_data.confidence[start]] From 9ee351e742a794e228d7e417394754559c0b7ee5 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 11 Jun 2023 00:45:00 +0200 Subject: [PATCH 36/40] - Fix plot sizes --- src/modules/plot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/modules/plot.py b/src/modules/plot.py index a29ca4c..a0aa263 100644 --- a/src/modules/plot.py +++ b/src/modules/plot.py @@ -26,8 +26,8 @@ def plot(pitched_data: PitchedData, conf_t, conf_f, conf_c = get_confidence(pitched_data, 0.4) - plt.ylim(0, 600) - plt.xlim(0, 50) + plt.ylim(0, max(conf_f)) + plt.xlim(0, pitched_data.times[-1]) plt.plot(conf_t, conf_f, linewidth=0.1) for i, data in enumerate(transcribed_data): @@ -44,7 +44,13 @@ def plot(pitched_data: PitchedData, facecolor='red', alpha=0.5) plt.gca().add_patch(rect) - plt.savefig(os.path.join(output_path, "plot.png"), dpi=3000) + + plt.xlabel("Time (s)") + plt.ylabel("Frequency (Hz)") + plt.ylim(0, 800) + dpi = 4000 + + plt.savefig(os.path.join(output_path, "plot.png"), dpi=dpi) def get_confidence( From 1d1ec8da087d2ca5b9d6052b569fba47ff0a0f06 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 17 Jun 2023 13:41:01 +0200 Subject: [PATCH 37/40] - Other language support --- README.md | 21 +++++++++++++++++---- src/Settings.py | 1 + src/UltraSinger.py | 5 ++++- src/modules/Speech_Recognition/Whisper.py | 17 +++++++++++++---- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 891603c..7652714 100644 --- a/README.md +++ b/README.md @@ -112,9 +112,11 @@ _Not all options working now!_ [transcription] # Default is whisper - --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2 >> ((default) is large-v2 - English-only model > tiny.en|base.en|small.en|medium.en - --vosk Needs model + --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2 >> ((default) is large-v2 + English-only model > tiny.en|base.en|small.en|medium.en + --align_model Use other languages model for Whisper provided from huggingface.co + + --vosk Needs model [pitcher] # Default is crepe @@ -163,12 +165,23 @@ Also keep in mind that while a larger model is more accurate, it also takes long #### Whisper -For the first test run, use the `tiny`, to be accurate use the `large-v2` model +For the first test run, use the `tiny`, to be accurate use the `large-v2` model. ```commandline -i XYZ --whisper large ``` +##### Whisper languages + +Currently provided default language models are `en, fr, de, es, it, ja, zh, nl, uk, pt`. +If the language is not in this list, you need to find a phoneme-based ASR model from +[huggingface model hub](https://huggingface.co). It will download automatically. + +Example for romanian: +```commandline +-i XYZ --align_model "gigant/romanian-wav2vec2" +``` + #### Vosk If you want to use `Vosk` than you need the model. It is not included. You can download it here [Link](https://alphacephei.com/vosk/models). diff --git a/src/Settings.py b/src/Settings.py index a025f14..93d5b25 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -17,6 +17,7 @@ class Settings: transcriber = "whisper" # whisper|vosk whisper_model = "large-v2" # Multilingual model tiny|base|small|medium|large-v1|large-v2 # English-only model tiny.en|base.en|small.en|medium.en + whisper_align_model = None # Model for other languages from huggingface.co e.g -> "gigant/romanian-wav2vec2" # Vosk vosk_model_path = "" # "models/vosk-model-small-en-us-0.15" diff --git a/src/UltraSinger.py b/src/UltraSinger.py index 38bbbfb..d866826 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -400,7 +400,7 @@ def transcribe_audio() -> (str, list[TranscribedData]): if settings.transcriber == "whisper": device = "cpu" if settings.force_whisper_cpu else settings.device transcribed_data, language = transcribe_with_whisper( - settings.mono_audio_path, settings.whisper_model, device) + settings.mono_audio_path, settings.whisper_model, device, settings.whisper_align_model) else: # vosk transcribed_data = transcribe_with_vosk( settings.mono_audio_path, settings.vosk_model_path @@ -729,6 +729,8 @@ def init_settings(argv: list[str]) -> None: elif opt in ("--whisper"): settings.transcriber = "whisper" settings.whisper_model = arg + elif opt in ("--align_model"): + settings.whisper_align_model = arg elif opt in ("--vosk"): settings.transcriber = "vosk" settings.vosk_model_path = arg @@ -765,6 +767,7 @@ def arg_options(): "crepe=", "vosk=", "whisper=", + "align_model=", "plot=", "hyphenation=", "disable_separation=", diff --git a/src/modules/Speech_Recognition/Whisper.py b/src/modules/Speech_Recognition/Whisper.py index e553a64..a827f3e 100644 --- a/src/modules/Speech_Recognition/Whisper.py +++ b/src/modules/Speech_Recognition/Whisper.py @@ -1,6 +1,7 @@ """Whisper Speech Recognition Module""" import whisperx +import sys from src.modules.console_colors import ( ULTRASINGER_HEAD, @@ -10,12 +11,14 @@ from src.modules.console_colors import ( from src.modules.Speech_Recognition.TranscribedData import TranscribedData -def transcribe_with_whisper(audio_path: str, model: str, device="cpu") -> (list[TranscribedData], str): +def transcribe_with_whisper(audio_path: str, model: str, device="cpu", model_name: str = None) -> (list[TranscribedData], str): """Transcribe with whisper""" print( f"{ULTRASINGER_HEAD} Loading {blue_highlighted('whisper')} with model {blue_highlighted(model)} and {red_highlighted(device)} as worker" ) + if model_name is not None: + print(f"{ULTRASINGER_HEAD} using alignment model {blue_highlighted(model_name)}") batch_size = 16 # reduce if low on GPU mem compute_type = ( @@ -26,6 +29,7 @@ def transcribe_with_whisper(audio_path: str, model: str, device="cpu") -> (list[ loaded_whisper_model = whisperx.load_model( model, device=device, compute_type=compute_type ) + audio = whisperx.load_audio(audio_path) print(f"{ULTRASINGER_HEAD} Transcribing {audio_path}") @@ -34,9 +38,14 @@ def transcribe_with_whisper(audio_path: str, model: str, device="cpu") -> (list[ language = result["language"] # load alignment model and metadata - model_a, metadata = whisperx.load_align_model( - language_code=language, device=device - ) + try: + model_a, metadata = whisperx.load_align_model(language_code=language, device=device, model_name=model_name) + except ValueError as ve: + print(f"{red_highlighted(f'{ve}')}" + f"\n" + f"{ULTRASINGER_HEAD} {red_highlighted('Error:')} Unknown language. " + f"Try add it with --align_model [hugingface].") + sys.exit(0) # align whisper output result_aligned = whisperx.align( From c4ecbea475d8817f07fc1acb67c07a46fd30d51f Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 17 Jun 2023 13:41:18 +0200 Subject: [PATCH 38/40] - fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7652714..84c6e07 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ But you can force cpu usage with the extra options `--force_whisper_cpu` and `-- With an GPU you can speed up the process and also the quality of the transcription and pitching is better. You need a cuda device for this to work. -If you use MAC than sorry, there is no cuda device for MAC machinges. +If you use MAC than sorry, there is no cuda device for MAC machines. #### Info From d82b655412083a29a6473672ab720139402cff5f Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 18 Jun 2023 01:36:03 +0200 Subject: [PATCH 39/40] - Fix missing symbols and optimize performance of hyphenation --- .../Speech_Recognition/test_hyphenation.py | 15 +++++ src/UltraSinger.py | 8 ++- src/modules/Speech_Recognition/hyphenation.py | 58 +++++++++++++++++-- 3 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 pytest/modules/Speech_Recognition/test_hyphenation.py diff --git a/pytest/modules/Speech_Recognition/test_hyphenation.py b/pytest/modules/Speech_Recognition/test_hyphenation.py new file mode 100644 index 0000000..9e7b77e --- /dev/null +++ b/pytest/modules/Speech_Recognition/test_hyphenation.py @@ -0,0 +1,15 @@ +"""Tests for hyphenation.py""" + +from src.modules.Speech_Recognition.hyphenation import hyphenation + + +def test_hypenation(): + """Test case for hyphenation function.""" + # test + assert hyphenation("begegnen", "de_DE") == ["be", "geg", "nen"] + assert hyphenation(".b,e~g'eg*nen, ", "de_DE") == [".b,e", "~g'eg", "*nen, "] + assert hyphenation("Abend, ", "de_AT") == None + assert hyphenation("Abend.", "de_AT") == None + + + diff --git a/src/UltraSinger.py b/src/UltraSinger.py index d866826..61bbea8 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -45,7 +45,7 @@ from src.modules.Pitcher.pitcher import ( get_pitch_with_crepe_file, ) from src.modules.Pitcher.pitched_data import PitchedData -from src.modules.Speech_Recognition.hyphenation import hyphenation, language_check +from src.modules.Speech_Recognition.hyphenation import hyphenation, language_check, create_hyphenator from src.modules.Speech_Recognition.Vosk import transcribe_with_vosk from src.modules.Speech_Recognition.Whisper import transcribe_with_whisper from src.modules.Ultrastar import ultrastar_score_calculator, ultrastar_writer, ultrastar_converter, ultrastar_parser @@ -230,9 +230,11 @@ def hyphenate_each_word(language: str, transcribed_data: list[TranscribedData]) return None sleep(0.1) - for i, data in tqdm(enumerate(transcribed_data)): + hyphenator = create_hyphenator(lang_region) + for i in tqdm(enumerate(transcribed_data)): + pos = i[0] hyphenated_word.append( - hyphenation(data.word, lang_region) + hyphenation(transcribed_data[pos].word, hyphenator) ) return hyphenated_word diff --git a/src/modules/Speech_Recognition/hyphenation.py b/src/modules/Speech_Recognition/hyphenation.py index 4d65b9c..22b857a 100644 --- a/src/modules/Speech_Recognition/hyphenation.py +++ b/src/modules/Speech_Recognition/hyphenation.py @@ -36,20 +36,66 @@ def contains_punctuation(word: str) -> bool: return any(elem in word for elem in string.punctuation) -def hyphenation(word: str, lang_region: str) -> list[str] | None: +def clean_word(word: str): + """Remove punctuation from word""" + cleaned_string = "" + removed_indices = [] + removed_symbols = [] + for i, char in enumerate(word): + if char not in string.punctuation and char not in " ": + cleaned_string += char + else: + removed_indices.append(i) + removed_symbols.append(char) + return cleaned_string, removed_indices, removed_symbols + + +def insert_removed_symbols(separated_array, removed_indices, symbols): + """Insert symbols into the syllables""" + result = [] + symbol_index = 0 + i = 0 + + # Add removed symbols to the syllables + for syllable in separated_array: + tmp = "" + for char in syllable: + if i in removed_indices: + tmp += symbols[symbol_index] + symbol_index += 1 + i += 1 + tmp += char + i += 1 + result.append(tmp) + + # Add remaining symbols to the last syllable + if symbol_index < len(symbols): + tmp = result[-1] + for i in range(symbol_index, len(symbols)): + tmp += symbols[i] + result[-1] = tmp + + return result + + +def create_hyphenator(lang_region: str) -> Hyphenator: + """Create hyphenator""" + hyphenator = Hyphenator(lang_region) + return hyphenator + + +def hyphenation(word: str, hyphenator: Hyphenator) -> list[str] | None: """Hyphenate word""" - if contains_punctuation(word): - return None - - hyphenator = Hyphenator(lang_region) - syllabus = hyphenator.syllables(word) + cleaned_string, removed_indices, removed_symbols = clean_word(word) + syllabus = hyphenator.syllables(cleaned_string) length = len(syllabus) if length > 1: hyphen = [] for i in range(length): hyphen.append(syllabus[i]) + hyphen = insert_removed_symbols(hyphen, removed_indices, removed_symbols) else: hyphen = None From bee527ccf687baba00d488a488b61b182140b9a1 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 18 Jun 2023 01:59:14 +0200 Subject: [PATCH 40/40] - Fix test --- pytest/modules/Speech_Recognition/test_hyphenation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pytest/modules/Speech_Recognition/test_hyphenation.py b/pytest/modules/Speech_Recognition/test_hyphenation.py index 9e7b77e..a177529 100644 --- a/pytest/modules/Speech_Recognition/test_hyphenation.py +++ b/pytest/modules/Speech_Recognition/test_hyphenation.py @@ -1,15 +1,16 @@ """Tests for hyphenation.py""" from src.modules.Speech_Recognition.hyphenation import hyphenation +from hyphen import Hyphenator def test_hypenation(): """Test case for hyphenation function.""" - # test - assert hyphenation("begegnen", "de_DE") == ["be", "geg", "nen"] - assert hyphenation(".b,e~g'eg*nen, ", "de_DE") == [".b,e", "~g'eg", "*nen, "] - assert hyphenation("Abend, ", "de_AT") == None - assert hyphenation("Abend.", "de_AT") == None + + assert hyphenation("begegnen", Hyphenator("de_DE")) == ["be", "geg", "nen"] + assert hyphenation(".b,e~g'eg*nen, ", Hyphenator("de_DE")) == [".b,e", "~g'eg", "*nen, "] + assert hyphenation("Abend, ", Hyphenator("de_AT")) == None + assert hyphenation("Abend.", Hyphenator("de_AT")) == None