-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fastspeech models #4337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
supotato6
wants to merge
11
commits into
PaddlePaddle:develop
Choose a base branch
from
supotato6:develop_fastspeech_item
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fastspeech models #4337
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
024ab46
fastspeech models
supotato6 87daa60
add model config
supotato6 869557e
config and readme
supotato6 b0888d8
change filename
supotato6 2425bc7
model file link
supotato6 fd10598
add module file
supotato6 d1ccc00
fix readme link
supotato6 4b5ed89
filename
supotato6 b34303c
filename1
supotato6 10db1c2
module methods
supotato6 98972c3
module methods init
supotato6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Global: | ||
model: G2PWModel | ||
mode: predict # only support predict | ||
device: gpu:0 | ||
output: "output" | ||
|
||
Predict: | ||
batch_size: 1 | ||
input: "欢迎使用飞桨" | ||
kernel_option: | ||
run_mode: paddle |
22 changes: 22 additions & 0 deletions
22
paddlex/configs/modules/text_to_speech_acoustic/fastspeech2_csmsc.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Global: | ||
model: fastspeech2_csmsc | ||
mode: predict # only support predict | ||
device: gpu:0 | ||
use_trt: False | ||
use_mkldnn: False | ||
cpu_threads: 1 | ||
precision: "fp32" | ||
output: "output" | ||
model_name: "fastspeech2_csmsc" | ||
speaker_dict: None | ||
lang: zh | ||
speaker_id: 0 | ||
|
||
Predict: | ||
batch_size: 1 | ||
model_dir: "fastspeech2csmsc" | ||
input: "今天天气真不错" | ||
lang: zh | ||
speaker_id: 0 | ||
kernel_option: | ||
run_mode: paddle |
22 changes: 22 additions & 0 deletions
22
paddlex/configs/modules/text_to_speech_vocoder/pwgan_csmsc.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Global: | ||
model: pwgan_csmsc | ||
mode: predict # only support predict | ||
device: gpu:0 | ||
use_trt: False | ||
use_mkldnn: False | ||
cpu_threads: 1 | ||
precision: "fp32" | ||
output: "output" | ||
model_name: "pwgan_csmsc" | ||
speaker_dict: None | ||
lang: zh | ||
speaker_id: 0 | ||
|
||
Predict: | ||
batch_size: 1 | ||
model_dir: "pwgan_csmsc" | ||
input: "今天天气真不错" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. input应该是npy或者tensor? |
||
lang: zh | ||
speaker_id: 0 | ||
kernel_option: | ||
run_mode: paddle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
paddlex/inference/common/batch_sampler/text_batch_sampler.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ....utils import logging | ||
from .base_batch_sampler import BaseBatchSampler | ||
|
||
|
||
class TextBatchSampler(BaseBatchSampler): | ||
def __init__(self): | ||
"""Initializes the BaseBatchSampler. | ||
|
||
Args: | ||
batch_size (int, optional): The size of each batch. Only support 1. | ||
""" | ||
super().__init__() | ||
self.batch_size = 1 | ||
|
||
def sample(self, inputs): | ||
"""Generate list of input file path. | ||
|
||
Args: | ||
inputs (str): file path. | ||
|
||
Yields: | ||
list: list of file path. | ||
""" | ||
if isinstance(inputs, str): | ||
yield [inputs] | ||
else: | ||
logging.warning( | ||
f"Not supported input data type! Only `str` are supported, but got: {input}." | ||
) | ||
|
||
@BaseBatchSampler.batch_size.setter | ||
def batch_size(self, batch_size): | ||
"""Sets the batch size. | ||
|
||
Args: | ||
batch_size (int): The batch size to set. | ||
|
||
Raises: | ||
Warning: If the batch size is not equal 1. | ||
""" | ||
# only support batch size 1 | ||
if batch_size != 1: | ||
logging.warning( | ||
f"audio batch sampler only support batch size 1, but got {batch_size}." | ||
) | ||
else: | ||
self._batch_size = batch_size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .base_result import BaseResult | ||
from .mixin import AudioMixin | ||
|
||
|
||
class BaseAudioResult(BaseResult, AudioMixin): | ||
"""Base class for computer vision results.""" | ||
|
||
INPUT_AUDIO_KEY = "input_audio" | ||
|
||
def __init__(self, data: dict) -> None: | ||
""" | ||
Initialize the BaseAudioResult. | ||
|
||
Args: | ||
data (dict): The initial data. | ||
|
||
Raises: | ||
AssertionError: If the required key (`BaseAudioResult.INPUT_AUDIO_KEY`) are not found in the data. | ||
""" | ||
|
||
super().__init__(data) | ||
AudioMixin.__init__(self,'wav') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# copyright (c) 2025 PaddlePaddle Authors. All Rights Reserve. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .predictor import TextToPinyinPredictor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# copyright (c) 2025 PaddlePaddle Authors. All Rights Reserve. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import numpy as np | ||
|
||
from ....utils.func_register import FuncRegister | ||
from ...common.batch_sampler import TextBatchSampler | ||
|
||
from ..base import BasePredictor | ||
from .result import TextToPinyinResult | ||
from ....modules.text_to_pinyin.model_list import MODELS | ||
|
||
|
||
class TextToPinyinPredictor(BasePredictor): | ||
|
||
entities = MODELS | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Initializes TextSegmentPredictor. | ||
|
||
Args: | ||
*args: Arbitrary positional arguments passed to the superclass. | ||
**kwargs: Arbitrary keyword arguments passed to the superclass. | ||
""" | ||
super().__init__(*args, **kwargs) | ||
self.model = self._build() | ||
|
||
def _build_batch_sampler(self): | ||
"""Builds and returns an TextBatchSampler instance. | ||
|
||
Returns: | ||
TextBatchSampler: An instance of TextBatchSampler. | ||
""" | ||
return TextBatchSampler() | ||
|
||
def _get_result_class(self): | ||
"""Returns the result class, TextToPinyinResult. | ||
|
||
Returns: | ||
type: The TextToPinyinResult class. | ||
""" | ||
return TextToPinyinResult | ||
|
||
def _build(self): | ||
"""Build the model. | ||
|
||
Returns: | ||
G2PWOnnxConverter: An instance of G2PWOnnxConverter. | ||
""" | ||
from .processors import ( | ||
G2PWOnnxConverter, | ||
) | ||
|
||
# build model | ||
model = G2PWOnnxConverter( | ||
model_dir=self.model_dir, style="pinyin", enable_non_tradional_chinese=True | ||
) | ||
return model | ||
|
||
def process(self, batch_data): | ||
""" | ||
Process a batch of data through the preprocessing, inference, and postprocessing. | ||
|
||
Args: | ||
batch_data (List[Union[str], ...]): A batch of input text data. | ||
|
||
Returns: | ||
dict: A dictionary containing the input path and result. The result include the output pinyin dict. | ||
""" | ||
result = self.model(batch_data[0]) | ||
return { | ||
"result": [result] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input 应该是phone?