LichtLiu commited on
Commit
81766a7
1 Parent(s): 0d230cc

update audio split

Browse files
Files changed (2) hide show
  1. app.py +18 -28
  2. 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
- # Split text into chunks that fit within the maximum token limit
51
- words = text.split() # Split the text into words
52
- chunks = []
53
- current_chunk = []
54
-
55
- for word in words:
56
- if len(current_chunk) + len(word) + 1 <= max_length: # +1 accounts for space between words
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
- # Split the input text into smaller chunks if necessary
72
- max_token_limit = 600 # Set the token limit for your model
73
- chunks = split_text_into_chunks(expression, max_token_limit)
 
 
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 chunk in chunks:
80
- inputs = processor(text=chunk, return_tensors="pt").to(device)
81
- speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
82
  audio_chunks.append(speech.cpu().numpy())
83
 
84
- # Concatenate the audio chunks into a single file
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
+ commit b8c7a08b2bbcfdee152786b6a7212a047c50fc85 (HEAD -> main, origin/main, origin/HEAD)
2
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
3
+ Date: Sun Oct 6 14:21:55 2024 +0200
4
+
5
+ state
6
+
7
+ commit 469ea347d5b8ea6d5404d7e88c4b4ab3f4abea07
8
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
9
+ Date: Sun Oct 6 14:15:30 2024 +0200
10
+
11
+ update history
12
+
13
+ commit 3665a4d6ca95c3a000e58ce1cb8a96fd34ecd9ce
14
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
15
+ Date: Sun Oct 6 14:11:30 2024 +0200
16
+
17
+ print
18
+
19
+ commit 96ad9b6e84215b238a689f0a5e4d33971114a2d7
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
+ commit 46e5c3d007799e62d711648538998e777fabca81
26
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
27
+ Date: Sun Oct 6 14:02:18 2024 +0200
28
+
29
+ delete history
30
+
31
+ commit a997e436dc12c9d1c0824216b9c274ffee7371f8
32
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
33
+ Date: Sun Oct 6 13:53:47 2024 +0200
34
+
35
+ update history
36
+
37
+ commit a743d0417f8168714ec629191b0d0c228c5b236e
38
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
39
+ Date: Sun Oct 6 13:51:41 2024 +0200
40
+
41
+ update
42
+
43
+ commit 2c12fc659c9e0f58f725b751b244de305ef31423
44
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
45
+ Date: Sun Oct 6 13:48:20 2024 +0200
46
+
47
+ update
48
+
49
+ commit c1aaa3ef2578af41e237a507c82ba8810b23129f
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
+ commit cbc1d5399d3c2b2ea2385503a96194c2aea7e5c7
56
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
57
+ Date: Sun Oct 6 13:41:12 2024 +0200
58
+
59
+ update
60
+
61
+ commit 5605340f569f7de28844f49d7c8216159326240a
62
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
63
+ Date: Sun Oct 6 13:26:52 2024 +0200
64
+
65
+ update 20241006
66
+
67
+ commit 9819d723446298f3846c4eca55c081d1ab6083a4
68
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
69
+ Date: Mon Sep 30 16:22:08 2024 +0200
70
+
71
+ update markdown
72
+
73
+ commit 60c04ae96546d672b6804699cd99623e15dea0b1
74
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
75
+ Date: Mon Sep 30 15:24:05 2024 +0200
76
+
77
+ call print
78
+
79
+ commit 08681846ade0af0fa2323113c1416fc0c2a5e345
80
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
81
+ Date: Mon Sep 30 15:06:04 2024 +0200
82
+
83
+ update
84
+
85
+ commit d99be9e3ac9f8e8148f3da866f94ae539e29d363
86
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
87
+ Date: Mon Sep 30 14:47:27 2024 +0200
88
+
89
+ edit prompt
90
+
91
+ commit 23136538c718c9a7683a5f9f729790050986066b (grafted)
92
+ Author: LichtLiu <LichtLiu@users.noreply.huggingface.co>
93
+ Date: Sun Sep 29 19:22:47 2024 +0200
94
+
95
+ update