ariG23498 HF Staff commited on
Commit
c71694a
·
verified ·
1 Parent(s): 5ab7493

Upload kyutai_pocket-tts_1.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. kyutai_pocket-tts_1.py +70 -0
kyutai_pocket-tts_1.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "pandas",
7
+ # "matplotlib",
8
+ # "protobuf",
9
+ # "torch",
10
+ # "sentencepiece",
11
+ # "torchvision",
12
+ # "transformers",
13
+ # "timm",
14
+ # "diffusers",
15
+ # "sentence-transformers",
16
+ # "accelerate",
17
+ # "peft",
18
+ # "slack-sdk",
19
+ # ]
20
+ # ///
21
+
22
+ try:
23
+ from pocket_tts import TTSModel
24
+ import scipy.io.wavfile
25
+
26
+ tts_model = TTSModel.load_model("kyutai/pocket-tts")
27
+ voice_state = tts_model.get_state_for_audio_prompt(
28
+ "hf://kyutai/tts-voices/alba-mackenna/casual.wav"
29
+ )
30
+ audio = tts_model.generate_audio(voice_state, "Hello world, this is a test.")
31
+ # Audio is a 1D torch tensor containing PCM data.
32
+ scipy.io.wavfile.write("output.wav", tts_model.sample_rate, audio.numpy())
33
+ with open('kyutai_pocket-tts_1.txt', 'w', encoding='utf-8') as f:
34
+ f.write('Everything was good in kyutai_pocket-tts_1.txt')
35
+ except Exception as e:
36
+ import os
37
+ from slack_sdk import WebClient
38
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
39
+ client.chat_postMessage(
40
+ channel='#hub-model-metadata-snippets-sprint',
41
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/kyutai_pocket-tts_1.txt|kyutai_pocket-tts_1.txt>',
42
+ )
43
+
44
+ with open('kyutai_pocket-tts_1.txt', 'a', encoding='utf-8') as f:
45
+ import traceback
46
+ f.write('''```CODE:
47
+ from pocket_tts import TTSModel
48
+ import scipy.io.wavfile
49
+
50
+ tts_model = TTSModel.load_model("kyutai/pocket-tts")
51
+ voice_state = tts_model.get_state_for_audio_prompt(
52
+ "hf://kyutai/tts-voices/alba-mackenna/casual.wav"
53
+ )
54
+ audio = tts_model.generate_audio(voice_state, "Hello world, this is a test.")
55
+ # Audio is a 1D torch tensor containing PCM data.
56
+ scipy.io.wavfile.write("output.wav", tts_model.sample_rate, audio.numpy())
57
+ ```
58
+
59
+ ERROR:
60
+ ''')
61
+ traceback.print_exc(file=f)
62
+
63
+ finally:
64
+ from huggingface_hub import upload_file
65
+ upload_file(
66
+ path_or_fileobj='kyutai_pocket-tts_1.txt',
67
+ repo_id='model-metadata/code_execution_files',
68
+ path_in_repo='kyutai_pocket-tts_1.txt',
69
+ repo_type='dataset',
70
+ )