jbetker commited on
Commit
8215af8
1 Parent(s): b07fb37

Add read script

Browse files
Files changed (3) hide show
  1. data/riding_hood.txt +54 -0
  2. do_tts.py +4 -6
  3. read.py +76 -0
data/riding_hood.txt ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Once upon a time there lived in a certain village a little country girl, the prettiest creature who was ever seen. Her mother was excessively fond of her; and her grandmother doted on her still more. This good woman had a little red riding hood made for her. It suited the girl so extremely well that everybody called her Little Red Riding Hood.
2
+ One day her mother, having made some cakes, said to her, "Go, my dear, and see how your grandmother is doing, for I hear she has been very ill. Take her a cake, and this little pot of butter."
3
+
4
+ Little Red Riding Hood set out immediately to go to her grandmother, who lived in another village.
5
+
6
+ As she was going through the wood, she met with a wolf, who had a very great mind to eat her up, but he dared not, because of some woodcutters working nearby in the forest. He asked her where she was going. The poor child, who did not know that it was dangerous to stay and talk to a wolf, said to him, "I am going to see my grandmother and carry her a cake and a little pot of butter from my mother."
7
+
8
+ "Does she live far off?" said the wolf
9
+
10
+ "Oh I say," answered Little Red Riding Hood; "it is beyond that mill you see there, at the first house in the village."
11
+
12
+ "Well," said the wolf, "and I'll go and see her too. I'll go this way and go you that, and we shall see who will be there first."
13
+
14
+ The wolf ran as fast as he could, taking the shortest path, and the little girl took a roundabout way, entertaining herself by gathering nuts, running after butterflies, and gathering bouquets of little flowers. It was not long before the wolf arrived at the old woman's house. He knocked at the door: tap, tap.
15
+
16
+ "Who's there?"
17
+
18
+ "Your grandchild, Little Red Riding Hood," replied the wolf, counterfeiting her voice; "who has brought you a cake and a little pot of butter sent you by mother."
19
+
20
+ The good grandmother, who was in bed, because she was somewhat ill, cried out, "Pull the bobbin, and the latch will go up."
21
+
22
+ The wolf pulled the bobbin, and the door opened, and then he immediately fell upon the good woman and ate her up in a moment, for it been more than three days since he had eaten. He then shut the door and got into the grandmother's bed, expecting Little Red Riding Hood, who came some time afterwards and knocked at the door: tap, tap.
23
+
24
+ "Who's there?"
25
+
26
+ Little Red Riding Hood, hearing the big voice of the wolf, was at first afraid; but believing her grandmother had a cold and was hoarse, answered, "It is your grandchild Little Red Riding Hood, who has brought you a cake and a little pot of butter mother sends you."
27
+
28
+ The wolf cried out to her, softening his voice as much as he could, "Pull the bobbin, and the latch will go up."
29
+
30
+ Little Red Riding Hood pulled the bobbin, and the door opened.
31
+
32
+ The wolf, seeing her come in, said to her, hiding himself under the bedclothes, "Put the cake and the little pot of butter upon the stool, and come get into bed with me."
33
+
34
+ Little Red Riding Hood took off her clothes and got into bed. She was greatly amazed to see how her grandmother looked in her nightclothes, and said to her, "Grandmother, what big arms you have!"
35
+
36
+ "All the better to hug you with, my dear."
37
+
38
+ "Grandmother, what big legs you have!"
39
+
40
+ "All the better to run with, my child."
41
+
42
+ "Grandmother, what big ears you have!"
43
+
44
+ "All the better to hear with, my child."
45
+
46
+ "Grandmother, what big eyes you have!"
47
+
48
+ "All the better to see with, my child."
49
+
50
+ "Grandmother, what big teeth you have got!"
51
+
52
+ "All the better to eat you up with."
53
+
54
+ And, saying these words, this wicked wolf fell upon Little Red Riding Hood, and ate her all up.
do_tts.py CHANGED
@@ -5,7 +5,7 @@ import torch
5
  import torch.nn.functional as F
6
  import torchaudio
7
 
8
- from api_new_autoregressive import TextToSpeech, load_conditioning
9
  from utils.audio import load_audio
10
  from utils.tokenizer import VoiceBpeTokenizer
11
 
@@ -18,6 +18,7 @@ if __name__ == '__main__':
18
  'harris': ['voices/harris/1.wav', 'voices/harris/2.wav'],
19
  'lescault': ['voices/lescault/1.wav', 'voices/lescault/2.wav'],
20
  'otto': ['voices/otto/1.wav', 'voices/otto/2.wav'],
 
21
  # Female voices
22
  'atkins': ['voices/atkins/1.wav', 'voices/atkins/2.wav'],
23
  'grace': ['voices/grace/1.wav', 'voices/grace/2.wav'],
@@ -27,8 +28,8 @@ if __name__ == '__main__':
27
 
28
  parser = argparse.ArgumentParser()
29
  parser.add_argument('-text', type=str, help='Text to speak.', default="I am a language model that has learned to speak.")
30
- parser.add_argument('-voice', type=str, help='Use a preset conditioning voice (defined above). Overrides cond_path.', default='dotrice,harris,lescault,otto,atkins,grace,kennard,mol')
31
- parser.add_argument('-num_samples', type=int, help='How many total outputs the autoregressive transformer should produce.', default=32)
32
  parser.add_argument('-batch_size', type=int, help='How many samples to process at once in the autoregressive model.', default=16)
33
  parser.add_argument('-num_diffusion_samples', type=int, help='Number of outputs that progress to the diffusion stage.', default=16)
34
  parser.add_argument('-output_path', type=str, help='Where to store outputs.', default='results/')
@@ -38,9 +39,6 @@ if __name__ == '__main__':
38
  tts = TextToSpeech(autoregressive_batch_size=args.batch_size)
39
 
40
  for voice in args.voice.split(','):
41
- tokenizer = VoiceBpeTokenizer()
42
- text = torch.IntTensor(tokenizer.encode(args.text)).unsqueeze(0).cuda()
43
- text = F.pad(text, (0,1)) # This may not be necessary.
44
  cond_paths = preselected_cond_voices[voice]
45
  conds = []
46
  for cond_path in cond_paths:
 
5
  import torch.nn.functional as F
6
  import torchaudio
7
 
8
+ from api import TextToSpeech, load_conditioning
9
  from utils.audio import load_audio
10
  from utils.tokenizer import VoiceBpeTokenizer
11
 
 
18
  'harris': ['voices/harris/1.wav', 'voices/harris/2.wav'],
19
  'lescault': ['voices/lescault/1.wav', 'voices/lescault/2.wav'],
20
  'otto': ['voices/otto/1.wav', 'voices/otto/2.wav'],
21
+ 'obama': ['voices/obama/1.wav', 'voices/obama/2.wav'],
22
  # Female voices
23
  'atkins': ['voices/atkins/1.wav', 'voices/atkins/2.wav'],
24
  'grace': ['voices/grace/1.wav', 'voices/grace/2.wav'],
 
28
 
29
  parser = argparse.ArgumentParser()
30
  parser.add_argument('-text', type=str, help='Text to speak.', default="I am a language model that has learned to speak.")
31
+ parser.add_argument('-voice', type=str, help='Use a preset conditioning voice (defined above). Overrides cond_path.', default='obama,dotrice,harris,lescault,otto,atkins,grace,kennard,mol')
32
+ parser.add_argument('-num_samples', type=int, help='How many total outputs the autoregressive transformer should produce.', default=128)
33
  parser.add_argument('-batch_size', type=int, help='How many samples to process at once in the autoregressive model.', default=16)
34
  parser.add_argument('-num_diffusion_samples', type=int, help='Number of outputs that progress to the diffusion stage.', default=16)
35
  parser.add_argument('-output_path', type=str, help='Where to store outputs.', default='results/')
 
39
  tts = TextToSpeech(autoregressive_batch_size=args.batch_size)
40
 
41
  for voice in args.voice.split(','):
 
 
 
42
  cond_paths = preselected_cond_voices[voice]
43
  conds = []
44
  for cond_path in cond_paths:
read.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+
4
+ import torch
5
+ import torch.nn.functional as F
6
+ import torchaudio
7
+
8
+ from api import TextToSpeech, load_conditioning
9
+ from utils.audio import load_audio
10
+ from utils.tokenizer import VoiceBpeTokenizer
11
+
12
+ def split_and_recombine_text(texts, desired_length=200, max_len=300):
13
+ # TODO: also split across '!' and '?'. Attempt to keep quotations together.
14
+ texts = [s.strip() + "." for s in texts.split('.')]
15
+
16
+ i = 0
17
+ while i < len(texts):
18
+ ltxt = texts[i]
19
+ if len(ltxt) >= desired_length or i == len(texts)-1:
20
+ i += 1
21
+ continue
22
+ if len(ltxt) + len(texts[i+1]) > max_len:
23
+ i += 1
24
+ continue
25
+ texts[i] = f'{ltxt} {texts[i+1]}'
26
+ texts.pop(i+1)
27
+ return texts
28
+
29
+ if __name__ == '__main__':
30
+ # These are voices drawn randomly from the training set. You are free to substitute your own voices in, but testing
31
+ # has shown that the model does not generalize to new voices very well.
32
+ preselected_cond_voices = {
33
+ # Male voices
34
+ 'dotrice': ['voices/dotrice/1.wav', 'voices/dotrice/2.wav'],
35
+ 'harris': ['voices/harris/1.wav', 'voices/harris/2.wav'],
36
+ 'lescault': ['voices/lescault/1.wav', 'voices/lescault/2.wav'],
37
+ 'otto': ['voices/otto/1.wav', 'voices/otto/2.wav'],
38
+ 'obama': ['voices/obama/1.wav', 'voices/obama/2.wav'],
39
+ 'carlin': ['voices/carlin/1.wav', 'voices/carlin/2.wav'],
40
+ # Female voices
41
+ 'atkins': ['voices/atkins/1.wav', 'voices/atkins/2.wav'],
42
+ 'grace': ['voices/grace/1.wav', 'voices/grace/2.wav'],
43
+ 'kennard': ['voices/kennard/1.wav', 'voices/kennard/2.wav'],
44
+ 'mol': ['voices/mol/1.wav', 'voices/mol/2.wav'],
45
+ 'lj': ['voices/lj/1.wav', 'voices/lj/2.wav'],
46
+ }
47
+
48
+ parser = argparse.ArgumentParser()
49
+ parser.add_argument('-textfile', type=str, help='A file containing the text to read.', default="data/riding_hood.txt")
50
+ parser.add_argument('-voice', type=str, help='Use a preset conditioning voice (defined above). Overrides cond_path.', default='dotrice')
51
+ parser.add_argument('-num_samples', type=int, help='How many total outputs the autoregressive transformer should produce.', default=256)
52
+ parser.add_argument('-batch_size', type=int, help='How many samples to process at once in the autoregressive model.', default=16)
53
+ parser.add_argument('-output_path', type=str, help='Where to store outputs.', default='results/longform/')
54
+ args = parser.parse_args()
55
+ os.makedirs(args.output_path, exist_ok=True)
56
+
57
+ with open(args.textfile, 'r', encoding='utf-8') as f:
58
+ text = ''.join([l for l in f.readlines()])
59
+ texts = split_and_recombine_text(text)
60
+
61
+ tts = TextToSpeech(autoregressive_batch_size=args.batch_size)
62
+
63
+ priors = []
64
+ for j, text in enumerate(texts):
65
+ cond_paths = preselected_cond_voices[args.voice]
66
+ conds = priors.copy()
67
+ for cond_path in cond_paths:
68
+ c = load_audio(cond_path, 22050)
69
+ conds.append(c)
70
+ gen = tts.tts(text, conds, num_autoregressive_samples=args.num_samples, temperature=.7, top_p=.7)
71
+ torchaudio.save(os.path.join(args.output_path, f'{j}.wav'), gen.squeeze(0).cpu(), 24000)
72
+
73
+ priors.append(torchaudio.functional.resample(gen, 24000, 22050).squeeze(0))
74
+ while len(priors) > 2:
75
+ priors.pop(0)
76
+