Skip to content

Conversation

@gau-nernst
Copy link
Contributor

What does this PR do?

Currently, to adjust the speed of generated audio with VitsModel, I have to modify the .speaking_rate attribute

from transformers import VitsModel, AutoTokenizer
import torch
from IPython.display import Audio

model_id = "facebook/mms-tts-eng"
model = VitsModel.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)

text = "some example text in the English language"
inputs = tokenizer(text, return_tensors="pt")

with torch.no_grad():
    model.speaking_rate = 2.0
    output = model(**inputs).waveform

Audio(output.numpy(), rate=model.config.sampling_rate)

To make it more convenient, I added speaking_rate as a forward argument, so speaking rate can be adjusted per-forward basis.

with torch.no_grad():
    output = model(**inputs, speaking_rate=0.5).waveform

The default behavior is preserved - if speaking_rate is not specified, it fallbacks to self.speaking_rate

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@eustlb

@Rocketknight1
Copy link
Member

cc @eustlb @ebezzam

@gau-nernst
Copy link
Contributor Author

@Rocketknight1 hi, any updates? thanks

@github-actions
Copy link
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: vits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants