S1m0neAI commited on
Commit
79728b0
1 Parent(s): 4ae4611

Upload 2 files

Browse files
Files changed (2) hide show
  1. model.pt +3 -0
  2. pipeline.py +42 -0
model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ae4c6d08511f62090c5fe5a02cd9effc57d147e8315f7fd477b20a20ce4d13b
3
+ size 113835419
pipeline.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Tuple
2
+ import subprocess
3
+
4
+ from torch import no_grad, package
5
+ import numpy as np
6
+ import os
7
+
8
+
9
+
10
+
11
+
12
+ class PreTrainedPipeline():
13
+ def __init__(self, path: str):
14
+ # Install espeak-ng
15
+ subprocess.run("apt-get update -y && apt-get install espeak-ng -y", shell=True,
16
+ universal_newlines=True, start_new_session=True)
17
+
18
+ # Init model
19
+ model_path = os.path.join(path, "model.pt")
20
+ importer = package.PackageImporter(model_path)
21
+ synt = importer.load_pickle("tts_models", "model")
22
+ self.synt = synt
23
+
24
+ self.tts_kwargs = {
25
+ "speaker_name": "uk",
26
+ "language_name": "uk",
27
+ }
28
+
29
+ self.sampling_rate = self.synt.output_sample_rate
30
+
31
+ def __call__(self, inputs: str) -> Tuple[np.array, int]:
32
+ """
33
+ Args:
34
+ inputs (:obj:`str`):
35
+ The text to generate audio from
36
+ Return:
37
+ A :obj:`np.array` and a :obj:`int`: The raw waveform as a numpy array, and the sampling rate as an int.
38
+ """
39
+ with no_grad():
40
+ waveforms = self.synt.tts(inputs, **self.tts_kwargs)
41
+ waveforms = np.array(waveforms, dtype=np.float32)
42
+ return waveforms, self.sampling_rate