voice-clone / texttovoice /serializers.py
renator's picture
update minio bucket
df4965a
raw
history blame
1.55 kB
from rest_framework import serializers
from .models import TextToSpeech
class TextToSpeechSerializer(serializers.Serializer):
text = serializers.CharField(default="In the quest for a sustainable future, renewable energy emerges as a beacon of hope")
speaker_wav = serializers.FileField()
language = serializers.CharField(default="en")
class TextToSpeechSerializerResponse(serializers.ModelSerializer):
created_by = serializers.SerializerMethodField()
class Meta:
model = TextToSpeech
fields = ['id', 'text', 'speaker_wav', 'output_wav', 'language', 'created_by']
# Ensure that all the fields you want to include are listed here
def get_created_by(self, obj):
return obj.created_by.username if obj.created_by else None
class TextToSpeechSerializerResponseWithURL(serializers.ModelSerializer):
speaker_wav_url = serializers.SerializerMethodField()
output_wav_url = serializers.SerializerMethodField()
created_by = serializers.SerializerMethodField()
class Meta:
model = TextToSpeech
fields = ['id', 'text', 'speaker_wav_url', 'output_wav_url', 'language', 'created_by']
# Add or remove fields as necessary
def get_speaker_wav_url(self, obj):
return self.context['view'].generate_presigned_url(obj.speaker_wav)
def get_output_wav_url(self, obj):
return self.context['view'].generate_presigned_url(obj.output_wav)
def get_created_by(self, obj):
return obj.created_by.username if obj.created_by else None