update audio split
Browse files- app.py +18 -28
- hell 3.10.15 +95 -0
app.py
CHANGED
@@ -46,42 +46,32 @@ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan").to(devic
|
|
46 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
47 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0).to(device)
|
48 |
|
49 |
-
def split_text_into_chunks(text, max_length):
|
50 |
-
#
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
current_chunk.append(word)
|
58 |
-
else:
|
59 |
-
# Join the current chunk into a string and append it to the list of chunks
|
60 |
-
chunks.append(' '.join(current_chunk))
|
61 |
-
# Start a new chunk
|
62 |
-
current_chunk = [word]
|
63 |
-
|
64 |
-
# Append the last chunk
|
65 |
-
if current_chunk:
|
66 |
-
chunks.append(' '.join(current_chunk))
|
67 |
-
|
68 |
-
return chunks
|
69 |
|
70 |
def textToSpeech(expression):
|
71 |
-
#
|
72 |
-
max_token_limit = 600 #
|
73 |
-
|
|
|
|
|
74 |
|
75 |
# Initialize an empty list to store the generated speech chunks
|
76 |
audio_chunks = []
|
77 |
|
78 |
-
# Process each chunk through the model
|
79 |
-
for
|
80 |
-
|
81 |
-
speech = model.generate_speech(
|
82 |
audio_chunks.append(speech.cpu().numpy())
|
83 |
|
84 |
-
# Concatenate the audio chunks into a single
|
85 |
final_audio = np.concatenate(audio_chunks)
|
86 |
|
87 |
# Get the current date and time for unique file naming
|
|
|
46 |
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
47 |
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0).to(device)
|
48 |
|
49 |
+
def split_text_into_chunks(text, processor, max_length):
|
50 |
+
# Tokenize the input text
|
51 |
+
tokens = processor(text, return_tensors="pt", truncation=False).input_ids[0]
|
52 |
+
|
53 |
+
# Split tokens into chunks
|
54 |
+
chunked_tokens = [tokens[i:i + max_length] for i in range(0, len(tokens), max_length)]
|
55 |
+
|
56 |
+
return chunked_tokens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
def textToSpeech(expression):
|
59 |
+
# Set the maximum token limit for your model
|
60 |
+
max_token_limit = 600 # The maximum token length the model can handle
|
61 |
+
|
62 |
+
# Tokenize and split the text into chunks based on tokens
|
63 |
+
token_chunks = split_text_into_chunks(expression, processor, max_token_limit)
|
64 |
|
65 |
# Initialize an empty list to store the generated speech chunks
|
66 |
audio_chunks = []
|
67 |
|
68 |
+
# Process each token chunk through the model
|
69 |
+
for token_chunk in token_chunks:
|
70 |
+
# Generate speech from the token chunk
|
71 |
+
speech = model.generate_speech(token_chunk.unsqueeze(0), speaker_embeddings, vocoder=vocoder)
|
72 |
audio_chunks.append(speech.cpu().numpy())
|
73 |
|
74 |
+
# Concatenate the audio chunks into a single array
|
75 |
final_audio = np.concatenate(audio_chunks)
|
76 |
|
77 |
# Get the current date and time for unique file naming
|
hell 3.10.15
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[33mcommit b8c7a08b2bbcfdee152786b6a7212a047c50fc85[m[33m ([m[1;36mHEAD -> [m[1;32mmain[m[33m, [m[1;31morigin/main[m[33m, [m[1;31morigin/HEAD[m[33m)[m
|
2 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
3 |
+
Date: Sun Oct 6 14:21:55 2024 +0200
|
4 |
+
|
5 |
+
state
|
6 |
+
|
7 |
+
[33mcommit 469ea347d5b8ea6d5404d7e88c4b4ab3f4abea07[m
|
8 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
9 |
+
Date: Sun Oct 6 14:15:30 2024 +0200
|
10 |
+
|
11 |
+
update history
|
12 |
+
|
13 |
+
[33mcommit 3665a4d6ca95c3a000e58ce1cb8a96fd34ecd9ce[m
|
14 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
15 |
+
Date: Sun Oct 6 14:11:30 2024 +0200
|
16 |
+
|
17 |
+
print
|
18 |
+
|
19 |
+
[33mcommit 96ad9b6e84215b238a689f0a5e4d33971114a2d7[m
|
20 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
21 |
+
Date: Sun Oct 6 14:08:38 2024 +0200
|
22 |
+
|
23 |
+
update history return
|
24 |
+
|
25 |
+
[33mcommit 46e5c3d007799e62d711648538998e777fabca81[m
|
26 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
27 |
+
Date: Sun Oct 6 14:02:18 2024 +0200
|
28 |
+
|
29 |
+
delete history
|
30 |
+
|
31 |
+
[33mcommit a997e436dc12c9d1c0824216b9c274ffee7371f8[m
|
32 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
33 |
+
Date: Sun Oct 6 13:53:47 2024 +0200
|
34 |
+
|
35 |
+
update history
|
36 |
+
|
37 |
+
[33mcommit a743d0417f8168714ec629191b0d0c228c5b236e[m
|
38 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
39 |
+
Date: Sun Oct 6 13:51:41 2024 +0200
|
40 |
+
|
41 |
+
update
|
42 |
+
|
43 |
+
[33mcommit 2c12fc659c9e0f58f725b751b244de305ef31423[m
|
44 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
45 |
+
Date: Sun Oct 6 13:48:20 2024 +0200
|
46 |
+
|
47 |
+
update
|
48 |
+
|
49 |
+
[33mcommit c1aaa3ef2578af41e237a507c82ba8810b23129f[m
|
50 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
51 |
+
Date: Sun Oct 6 13:45:29 2024 +0200
|
52 |
+
|
53 |
+
update new_history
|
54 |
+
|
55 |
+
[33mcommit cbc1d5399d3c2b2ea2385503a96194c2aea7e5c7[m
|
56 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
57 |
+
Date: Sun Oct 6 13:41:12 2024 +0200
|
58 |
+
|
59 |
+
update
|
60 |
+
|
61 |
+
[33mcommit 5605340f569f7de28844f49d7c8216159326240a[m
|
62 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
63 |
+
Date: Sun Oct 6 13:26:52 2024 +0200
|
64 |
+
|
65 |
+
update 20241006
|
66 |
+
|
67 |
+
[33mcommit 9819d723446298f3846c4eca55c081d1ab6083a4[m
|
68 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
69 |
+
Date: Mon Sep 30 16:22:08 2024 +0200
|
70 |
+
|
71 |
+
update markdown
|
72 |
+
|
73 |
+
[33mcommit 60c04ae96546d672b6804699cd99623e15dea0b1[m
|
74 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
75 |
+
Date: Mon Sep 30 15:24:05 2024 +0200
|
76 |
+
|
77 |
+
call print
|
78 |
+
|
79 |
+
[33mcommit 08681846ade0af0fa2323113c1416fc0c2a5e345[m
|
80 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
81 |
+
Date: Mon Sep 30 15:06:04 2024 +0200
|
82 |
+
|
83 |
+
update
|
84 |
+
|
85 |
+
[33mcommit d99be9e3ac9f8e8148f3da866f94ae539e29d363[m
|
86 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
87 |
+
Date: Mon Sep 30 14:47:27 2024 +0200
|
88 |
+
|
89 |
+
edit prompt
|
90 |
+
|
91 |
+
[33mcommit 23136538c718c9a7683a5f9f729790050986066b[m[33m ([m[1;34mgrafted[m[33m)[m
|
92 |
+
Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
|
93 |
+
Date: Sun Sep 29 19:22:47 2024 +0200
|
94 |
+
|
95 |
+
update
|