Spaces:
Configuration error
Configuration error
checking times
Browse files- Dockerfile +2 -1
- project.log +0 -0
- texttovoice/views.py +26 -13
Dockerfile
CHANGED
@@ -38,7 +38,8 @@ COPY packages/matching.py /usr/local/lib/python3.10/site-packages/librosa/util/m
|
|
38 |
COPY packages/spectrum.py /usr/local/lib/python3.10/site-packages/librosa/core/spectrum.py
|
39 |
COPY packages/pitch.py /usr/local/lib/python3.10/site-packages/librosa/core/pitch.py
|
40 |
RUN chmod -R 777 /usr/local/lib/python3.10/site-packages/librosa \
|
41 |
-
&& chmod 777 /tmp && mkdir /.local && chmod -R 777 /.local && mkdir /.cache && chmod -R 777 /.cache
|
|
|
42 |
|
43 |
# Set the environment variable for the NUMBA cache directory
|
44 |
|
|
|
38 |
COPY packages/spectrum.py /usr/local/lib/python3.10/site-packages/librosa/core/spectrum.py
|
39 |
COPY packages/pitch.py /usr/local/lib/python3.10/site-packages/librosa/core/pitch.py
|
40 |
RUN chmod -R 777 /usr/local/lib/python3.10/site-packages/librosa \
|
41 |
+
&& chmod 777 /tmp && mkdir /.local && chmod -R 777 /.local && mkdir /.cache && chmod -R 777 /.cache && \
|
42 |
+
mkdir /.config && chmod -R 777 /.config
|
43 |
|
44 |
# Set the environment variable for the NUMBA cache directory
|
45 |
|
project.log
ADDED
The diff for this file is too large to render.
See raw diff
|
|
texttovoice/views.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import os
|
2 |
import uuid
|
|
|
|
|
|
|
3 |
from django.http import FileResponse
|
4 |
from rest_framework import status
|
5 |
from rest_framework.response import Response
|
@@ -14,6 +17,9 @@ from drf_yasg import openapi
|
|
14 |
from drf_yasg.utils import swagger_auto_schema
|
15 |
|
16 |
|
|
|
|
|
|
|
17 |
class TextToSpeechCreateView(CreateAPIView):
|
18 |
serializer_class = TextToSpeechSerializer
|
19 |
authentication_classes = [TokenAuthentication] # Apply token authentication
|
@@ -43,19 +49,16 @@ class TextToSpeechCreateView(CreateAPIView):
|
|
43 |
def create(self, request, *args, **kwargs):
|
44 |
serializer = self.get_serializer(data=request.data)
|
45 |
if serializer.is_valid():
|
|
|
46 |
text = serializer.validated_data.get("text")
|
47 |
speaker_wav = serializer.validated_data.get("speaker_wav")
|
48 |
language = serializer.validated_data.get("language")
|
49 |
output_filename = f"output_{uuid.uuid4()}.wav"
|
50 |
|
51 |
-
#
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
# Check if the directory exists and create it if it doesn't
|
56 |
-
if not os.path.exists(tmp_dir):
|
57 |
-
os.makedirs(tmp_dir)
|
58 |
-
print("before creating the speaker file path", os.path)
|
59 |
|
60 |
# Save the uploaded speaker file to a temporary location
|
61 |
speaker_file_path = os.path.join('/tmp', speaker_wav.name)
|
@@ -63,12 +66,16 @@ class TextToSpeechCreateView(CreateAPIView):
|
|
63 |
for chunk in speaker_wav.chunks():
|
64 |
destination.write(chunk)
|
65 |
|
66 |
-
print("after creating the speaker file path",speaker_file_path)
|
67 |
-
|
68 |
# Generate speech using tts.tts_to_file
|
69 |
-
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=
|
70 |
tts.tts_to_file(text=text, file_path=output_filename, speaker_wav=speaker_file_path, language=language)
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Define a function to delete the output file
|
73 |
def file_iterator(file_name):
|
74 |
with open(file_name, 'rb') as f:
|
@@ -86,10 +93,16 @@ class TextToSpeechCreateView(CreateAPIView):
|
|
86 |
# TextToSpeech.objects.create(
|
87 |
# text=text,
|
88 |
# speaker_wav=speaker_wav,
|
|
|
89 |
# language=language,
|
90 |
# created_by=request.user # Assign the authenticated user here
|
91 |
-
#
|
92 |
-
response = FileResponse(
|
|
|
|
|
|
|
|
|
|
|
93 |
return response
|
94 |
|
95 |
# except Exception as e:
|
|
|
1 |
import os
|
2 |
import uuid
|
3 |
+
import time
|
4 |
+
import logging # Import the logging module
|
5 |
+
import torch
|
6 |
from django.http import FileResponse
|
7 |
from rest_framework import status
|
8 |
from rest_framework.response import Response
|
|
|
17 |
from drf_yasg.utils import swagger_auto_schema
|
18 |
|
19 |
|
20 |
+
# Initialize logger at module level
|
21 |
+
logger = logging.getLogger(__name__)
|
22 |
+
|
23 |
class TextToSpeechCreateView(CreateAPIView):
|
24 |
serializer_class = TextToSpeechSerializer
|
25 |
authentication_classes = [TokenAuthentication] # Apply token authentication
|
|
|
49 |
def create(self, request, *args, **kwargs):
|
50 |
serializer = self.get_serializer(data=request.data)
|
51 |
if serializer.is_valid():
|
52 |
+
gpu_available = torch.cuda.is_available()
|
53 |
text = serializer.validated_data.get("text")
|
54 |
speaker_wav = serializer.validated_data.get("speaker_wav")
|
55 |
language = serializer.validated_data.get("language")
|
56 |
output_filename = f"output_{uuid.uuid4()}.wav"
|
57 |
|
58 |
+
# Log the start time
|
59 |
+
start_time = time.time()
|
60 |
+
print("start", start_time)
|
61 |
+
logger.info(f"start time: {start_time} ")
|
|
|
|
|
|
|
|
|
62 |
|
63 |
# Save the uploaded speaker file to a temporary location
|
64 |
speaker_file_path = os.path.join('/tmp', speaker_wav.name)
|
|
|
66 |
for chunk in speaker_wav.chunks():
|
67 |
destination.write(chunk)
|
68 |
|
|
|
|
|
69 |
# Generate speech using tts.tts_to_file
|
70 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2", gpu=gpu_available)
|
71 |
tts.tts_to_file(text=text, file_path=output_filename, speaker_wav=speaker_file_path, language=language)
|
72 |
|
73 |
+
# Log the end time
|
74 |
+
end_time = time.time()
|
75 |
+
|
76 |
+
# Calculate the processing time
|
77 |
+
processing_time = end_time - start_time
|
78 |
+
|
79 |
# Define a function to delete the output file
|
80 |
def file_iterator(file_name):
|
81 |
with open(file_name, 'rb') as f:
|
|
|
93 |
# TextToSpeech.objects.create(
|
94 |
# text=text,
|
95 |
# speaker_wav=speaker_wav,
|
96 |
+
# output_wav=output_filename,
|
97 |
# language=language,
|
98 |
# created_by=request.user # Assign the authenticated user here
|
99 |
+
# )
|
100 |
+
response = FileResponse(output_filename, as_attachment=True, content_type='audio/wav')
|
101 |
+
|
102 |
+
# Log the processing time using the logger
|
103 |
+
logger.info(f"start time: {start_time} , end time: {end_time} and Processing time: {processing_time} seconds")
|
104 |
+
print(f"start time: {start_time} , end time: {end_time} and Processing time: {processing_time} seconds")
|
105 |
+
|
106 |
return response
|
107 |
|
108 |
# except Exception as e:
|