Skip to content
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

api_server doesn't handle json audio data as base64 string #776

Closed
6 tasks done
MithrilMan opened this issue Dec 21, 2024 · 2 comments
Closed
6 tasks done

api_server doesn't handle json audio data as base64 string #776

MithrilMan opened this issue Dec 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@MithrilMan
Copy link
Contributor

MithrilMan commented Dec 21, 2024

Self Checks

  • This template is only for bug reports. For questions, please visit Discussions.
  • I have thoroughly reviewed the project documentation (installation, training, inference) but couldn't find information to solve my problem. English 中文 日本語 Portuguese (Brazil)
  • I have searched for existing issues, including closed ones. Search issues
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template and fill in all required fields.

Cloud or Self Hosted

Self Hosted (Docker)

Environment Details

latest docker image ( sha256:40c9620c1dfd8efb1063a5826e72243efafc5f19784af5fa0603238e06b7dd62 )

Steps to Reproduce

try to invoke the api_server endpoint passing a base64 reference

POST http://127.0.0.1:18080/v1/tts
Content-Type: application/json
{
    "text": "Ciao come va? tutto bene?",
    "format":"wav",
    "references": [
        {
            "audio": "PUT_A_BASE_64_AUDIO_DATA_HERE",
            "text": "Hello, how are you?"
        }
    ]
}

✔️ Expected Behavior

Base64 is the common way to pass binary array using json, this should be handled

I fixed it in my use case by updating schema.py ServeReferenceAudio class this way

import base64
from pydantic import model_validator

class ServeReferenceAudio(BaseModel):
    audio: bytes
    text: str
    
    @model_validator(mode="before")
    def decode_audio(cls, values):
        audio = values.get("audio")
        if isinstance(audio, str) and len(audio) > 255:  # Check if audio is a string (Base64)
            try:
                values["audio"] = base64.b64decode(audio)
            except Exception as e:
                # If the audio is not a valid base64 string, we will just ignore it and let the server handle it
                pass
        return values

    def __repr__(self) -> str:
        return f"ServeReferenceAudio(text={self.text!r}, audio_size={len(self.audio)})"

I don't know if it's still compatible with other use cases or if there is a better way to handle this scenario (I'm not used to python)
I added a check for length > 255 so it shouldn't interferee with a path (I saw a similar check in generate.py

If you want I can submit a PR

❌ Actual Behavior

it throws an error about invalid data

@MithrilMan
Copy link
Contributor Author

I've added the PR

#777

@MithrilMan
Copy link
Contributor Author

implemented in #777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant