gdnartea commited on
Commit
c0451b6
1 Parent(s): 18448b8

Rename temp_store to temp_store.py

Browse files
Files changed (2) hide show
  1. temp_store +0 -0
  2. temp_store.py +60 -0
temp_store DELETED
File without changes
temp_store.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import torch
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM, VitsModel
5
+ from nemo.collections.asr.models import EncDecMultiTaskModel
6
+
7
+
8
+ # load speech to text model
9
+ canary_model = EncDecMultiTaskModel.from_pretrained('nvidia/canary-1b')
10
+ canary_model.eval()
11
+ canary_model.to('cpu')
12
+
13
+ # update decode params
14
+ canary_model.change_decoding_strategy(None)
15
+ decode_cfg = canary_model.cfg.decoding
16
+ decode_cfg.beam.beam_size = 1
17
+ canary_model.change_decoding_strategy(decode_cfg)
18
+
19
+
20
+
21
+
22
+ # Load the text processing model and tokenizer
23
+ proc_tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
24
+ proc_model = AutoModelForCausalLM.from_pretrained(
25
+ "microsoft/Phi-3-mini-4k-instruct",
26
+ trust_remote_code=True,
27
+ )
28
+ proc_model.eval()
29
+ proc_model.to('cpu')
30
+
31
+
32
+ # Load the TTS model
33
+ tts_model = VitsModel.from_pretrained("facebook/mms-tts-eng")
34
+ tts_tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
35
+ tts_model.eval()
36
+ tts_model.to('cpu')
37
+
38
+
39
+ def process_speech(speech):
40
+ # Convert the speech to text
41
+ transcription = canary_model.transcribe(
42
+ speech,
43
+ logprobs=False,
44
+ )
45
+
46
+ # Process the text
47
+ inputs = proc_tokenizer.encode(transcription + proc_tokenizer.eos_token, return_tensors='pt')
48
+ outputs = proc_model.generate(inputs, max_length=100, temperature=0.7, pad_token_id=proc_tokenizer.eos_token_id)
49
+ text = proc_tokenizer.decode(outputs[0], skip_special_tokens=True)
50
+ processed_text = tts_tokenizer(text, return_tensors="pt")
51
+
52
+ # Convert the processed text to speech
53
+ with torch.no_grad():
54
+ audio = tts_model(**inputs).waveform
55
+
56
+ return audio
57
+
58
+ iface = gr.Interface(fn=process_speech, inputs=gr.inputs.Audio(source="microphone"), outputs="audio")
59
+
60
+ iface.launch()