Revert direct file send.
Browse files- handler.py +10 -12
handler.py
CHANGED
|
@@ -3,7 +3,7 @@ import numpy as np
|
|
| 3 |
import torch
|
| 4 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
| 5 |
from datasets import load_dataset
|
| 6 |
-
import soundfile as sf
|
| 7 |
from typing import Dict, List, Any
|
| 8 |
|
| 9 |
|
|
@@ -36,20 +36,18 @@ class EndpointHandler:
|
|
| 36 |
|
| 37 |
speech = self.model.generate_speech(inputs["input_ids"], self.speaker_embeddings, vocoder=self.vocoder)
|
| 38 |
|
| 39 |
-
filename = "current_sample.wav"
|
| 40 |
|
| 41 |
# Write the response audio to a file
|
| 42 |
-
sf.write(filename, speech.numpy(), samplerate=16000)
|
| 43 |
|
| 44 |
-
return send_file(filename, mimetype='audio/wav', as_attachment=True, attachment_filename=filename)
|
| 45 |
-
|
| 46 |
# Return the expected response format
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
handler = EndpointHandler()
|
|
|
|
| 3 |
import torch
|
| 4 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
| 5 |
from datasets import load_dataset
|
| 6 |
+
#import soundfile as sf
|
| 7 |
from typing import Dict, List, Any
|
| 8 |
|
| 9 |
|
|
|
|
| 36 |
|
| 37 |
speech = self.model.generate_speech(inputs["input_ids"], self.speaker_embeddings, vocoder=self.vocoder)
|
| 38 |
|
| 39 |
+
#filename = "current_sample.wav"
|
| 40 |
|
| 41 |
# Write the response audio to a file
|
| 42 |
+
#sf.write(filename, speech.numpy(), samplerate=16000)
|
| 43 |
|
|
|
|
|
|
|
| 44 |
# Return the expected response format
|
| 45 |
+
return {
|
| 46 |
+
"statusCode": 200,
|
| 47 |
+
"body": {
|
| 48 |
+
"audio": speech.numpy(), # Consider encoding this to a suitable format
|
| 49 |
+
"sampling_rate": 16000
|
| 50 |
+
}
|
| 51 |
+
}
|
| 52 |
|
| 53 |
handler = EndpointHandler()
|