tdnathmlenthusiast commited on
Commit
e2ff519
1 Parent(s): 23cc0d5

german tts

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -35
  2. README.md +13 -13
  3. app.py +71 -0
  4. requirements.txt +15 -0
.gitattributes CHANGED
@@ -1,35 +1,35 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,13 @@
1
- ---
2
- title: German TTS
3
- emoji: 🐢
4
- colorFrom: green
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 5.3.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: Technical Vocabulary
3
+ emoji: 👁
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 5.1.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import os
4
+ from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
5
+ from datasets import load_dataset, Audio
6
+ import numpy as np
7
+ from speechbrain.inference import EncoderClassifier
8
+
9
+ # Load models and processor
10
+ processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
11
+ model = SpeechT5ForTextToSpeech.from_pretrained("tdnathmlenthusiast/speecht5_finetuned_German_dataset")
12
+ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
13
+
14
+ # Load speaker encoder
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ speaker_model = EncoderClassifier.from_hparams(
17
+ source="speechbrain/spkrec-xvect-voxceleb",
18
+ run_opts={"device": device},
19
+ savedir=os.path.join("/tmp", "speechbrain/spkrec-xvect-voxceleb")
20
+ )
21
+
22
+ def create_speaker_embedding(waveform):
23
+ with torch.no_grad():
24
+ speaker_embeddings = speaker_model.encode_batch(torch.tensor(waveform))
25
+ speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=2)
26
+ speaker_embeddings = speaker_embeddings.squeeze().cpu().numpy()
27
+ return speaker_embeddings
28
+
29
+ # Load a sample from the dataset for speaker embedding
30
+ try:
31
+ dataset = load_dataset(""Thorsten-Voice/TV-44kHz-Full", "TV-2023.09-Hessisch", split="train", trust_remote_code=True)
32
+ dataset = dataset.cast_column("audio", Audio(sampling_rate=16000))
33
+ sample = dataset[10]
34
+ speaker_embedding = create_speaker_embedding(sample['audio']['array'])
35
+ except Exception as e:
36
+ print(f"Error loading dataset: {e}")
37
+ # Use a random speaker embedding as fallback
38
+ speaker_embedding = torch.randn(1, 512)
39
+
40
+
41
+ def text_to_speech(text):
42
+ # Clean up text
43
+ replacements = [
44
+ ("0", "zero"),
45
+ ("1", "one"),
46
+ ("2", "two"),
47
+ ("3", "three"),
48
+ ("4", "four"),
49
+ ("5", "five"),
50
+ ("6", "six"),
51
+ ("7", "seven"),
52
+ ("8", "eight"),
53
+ ("9", "nine"),
54
+ ("_", " ")
55
+ ]
56
+ for src, dst in replacements:
57
+ text = text.replace(src, dst)
58
+
59
+ inputs = processor(text=text, return_tensors="pt")
60
+ speech = model.generate_speech(inputs["input_ids"], speaker_embedding, vocoder=vocoder)
61
+ return (16000, speech.numpy())
62
+
63
+ iface = gr.Interface(
64
+ fn=text_to_speech,
65
+ inputs="text",
66
+ outputs="audio",
67
+ title="German Text-to-Speech Using T5 by Tirtha Debnath ",
68
+ description="Enter German text to convert to speech"
69
+ )
70
+
71
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pip
2
+ git+https://github.com/huggingface/transformers.git
3
+ accelerate
4
+ datasets
5
+ soundfile
6
+ speechbrain
7
+ torch
8
+ gradio
9
+ spaces
10
+ python_multipart
11
+ huggingface-hub
12
+ hf-transfer
13
+ protobuf
14
+ click
15
+ pydantic