|
from transformers import pipeline |
|
from typing import Any |
|
|
|
class EndpointHandler(): |
|
def __init__(self, path=""): |
|
|
|
self.pipeline = pipeline("text-to-speech", model=path, device=0) |
|
|
|
def __call__(self, data: Any) -> Any: |
|
inputs = data.pop("inputs", data) |
|
parameters = data.pop("parameters", None) |
|
|
|
|
|
if parameters is not None: |
|
prediction = self.pipeline(inputs, **parameters) |
|
else: |
|
prediction = self.pipeline(inputs) |
|
|
|
|
|
audio_array = prediction['audio'] |
|
sampling_rate = prediction['sampling_rate'] |
|
|
|
|
|
return { |
|
"audio": audio_array, |
|
"sampling_rate": sampling_rate |
|
} |