shukdevdatta123 commited on
Commit
994a224
·
verified ·
1 Parent(s): 0a51a48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from bark import SAMPLE_RATE, generate_audio, preload_models
 
3
  from scipy.io.wavfile import write as write_wav
4
  import tempfile
5
  import librosa
@@ -39,20 +40,28 @@ def preprocess_audio_to_npz(audio_path):
39
  # Ensure audio is a float32 array
40
  audio = audio.astype(np.float32)
41
 
42
- # Generate semantic tokens directly using Bark's internal processing
43
- # Since HuBERT models are not implemented, we rely on generate_audio's history prompt
44
- # This is a simplified approach assuming Bark can handle raw audio for history prompt
45
  with torch.device("cpu"):
46
- # Generate audio tokens to create a history prompt
47
- # We use a dummy text to generate a history prompt from the audio
48
  dummy_text = "Dummy text for history prompt generation."
49
- audio_array = generate_audio(dummy_text, history_prompt=audio_path)
50
 
51
- # Save the audio array as a temporary .npz file
 
 
 
 
 
 
 
 
52
  history_prompt = {
53
- "audio": audio_array
 
 
54
  }
55
 
 
56
  with tempfile.NamedTemporaryFile(suffix=".npz", delete=False) as temp_file:
57
  np.savez(temp_file.name, **history_prompt)
58
  npz_path = temp_file.name
 
1
  import gradio as gr
2
  from bark import SAMPLE_RATE, generate_audio, preload_models
3
+ from bark.generation import generate_text_semantic, text_to_semantic
4
  from scipy.io.wavfile import write as write_wav
5
  import tempfile
6
  import librosa
 
40
  # Ensure audio is a float32 array
41
  audio = audio.astype(np.float32)
42
 
 
 
 
43
  with torch.device("cpu"):
44
+ # Generate semantic tokens from the audio
45
+ # Use a dummy text to initialize the semantic token generation
46
  dummy_text = "Dummy text for history prompt generation."
47
+ semantic_tokens = text_to_semantic(dummy_text, temp=0.7, silent=True)
48
 
49
+ # Generate coarse tokens from semantic tokens
50
+ coarse_tokens = generate_text_semantic(
51
+ semantic_tokens=semantic_tokens,
52
+ max_gen_len=512,
53
+ temp=0.7,
54
+ silent=True
55
+ )
56
+
57
+ # Create history prompt dictionary
58
  history_prompt = {
59
+ "semantic_prompt": semantic_tokens,
60
+ "coarse_prompt": coarse_tokens,
61
+ "fine_prompt": coarse_tokens # Fine prompt is often same as coarse for Bark
62
  }
63
 
64
+ # Save to temporary .npz file
65
  with tempfile.NamedTemporaryFile(suffix=".npz", delete=False) as temp_file:
66
  np.savez(temp_file.name, **history_prompt)
67
  npz_path = temp_file.name