Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	Update KOKORO/utils.py
Browse files- KOKORO/utils.py +12 -2
    	
        KOKORO/utils.py
    CHANGED
    
    | @@ -274,8 +274,10 @@ def podcast(MODEL, device, gen_text, speed=1.0, trim=0.5, pad_between_segments=0 | |
| 274 | 
             
                    output_file = remove_silence_function(output_file, minimum_silence=minimum_silence)
         | 
| 275 |  | 
| 276 | 
             
                return output_file
         | 
| 277 | 
            -
             | 
|  | |
| 278 | 
             
            def tts(MODEL,device,text, voice_name, speed=1.0, trim=0.5, pad_between_segments=0.5, output_file="",remove_silence=True,minimum_silence=50):
         | 
|  | |
| 279 | 
             
                language = voice_name[0]
         | 
| 280 | 
             
                voice_pack_path = f"./KOKORO/voices/{voice_name}.pt"
         | 
| 281 | 
             
                if voice_name.endswith(".pt"):
         | 
| @@ -283,7 +285,14 @@ def tts(MODEL,device,text, voice_name, speed=1.0, trim=0.5, pad_between_segments | |
| 283 | 
             
                    voice_pack_path=voice_name
         | 
| 284 | 
             
                text=clean_text(text)
         | 
| 285 | 
             
                segments = large_text(text, language)
         | 
| 286 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 287 | 
             
                speed = clamp_speed(speed)
         | 
| 288 | 
             
                trim = clamp_trim(trim)
         | 
| 289 | 
             
                silence_duration = clamp_trim(pad_between_segments)
         | 
| @@ -343,3 +352,4 @@ def tts_file_name(text): | |
| 343 | 
             
                # Construct the file name
         | 
| 344 | 
             
                file_name = f"{temp_folder}/{truncated_text}_{random_string}.wav"
         | 
| 345 | 
             
                return file_name
         | 
|  | 
|  | |
| 274 | 
             
                    output_file = remove_silence_function(output_file, minimum_silence=minimum_silence)
         | 
| 275 |  | 
| 276 | 
             
                return output_file
         | 
| 277 | 
            +
            old_voice_pack_path=""
         | 
| 278 | 
            +
            old_VOICEPACK=None
         | 
| 279 | 
             
            def tts(MODEL,device,text, voice_name, speed=1.0, trim=0.5, pad_between_segments=0.5, output_file="",remove_silence=True,minimum_silence=50):
         | 
| 280 | 
            +
                global old_voice_pack_path,old_VOICEPACK
         | 
| 281 | 
             
                language = voice_name[0]
         | 
| 282 | 
             
                voice_pack_path = f"./KOKORO/voices/{voice_name}.pt"
         | 
| 283 | 
             
                if voice_name.endswith(".pt"):
         | 
|  | |
| 285 | 
             
                    voice_pack_path=voice_name
         | 
| 286 | 
             
                text=clean_text(text)
         | 
| 287 | 
             
                segments = large_text(text, language)
         | 
| 288 | 
            +
                if (old_voice_pack_path!=voice_pack_path)or ("weighted_normalised_voices.pt" in voice_pack_path):
         | 
| 289 | 
            +
                    VOICEPACK = torch.load(voice_pack_path, weights_only=True).to(device)
         | 
| 290 | 
            +
                    old_voice_pack_path=voice_pack_path
         | 
| 291 | 
            +
                    old_VOICEPACK=VOICEPACK
         | 
| 292 | 
            +
                    # print("Loaded new voice pack")
         | 
| 293 | 
            +
                else:
         | 
| 294 | 
            +
                    VOICEPACK=old_VOICEPACK
         | 
| 295 | 
            +
                    # print("Using old voice pack")
         | 
| 296 | 
             
                speed = clamp_speed(speed)
         | 
| 297 | 
             
                trim = clamp_trim(trim)
         | 
| 298 | 
             
                silence_duration = clamp_trim(pad_between_segments)
         | 
|  | |
| 352 | 
             
                # Construct the file name
         | 
| 353 | 
             
                file_name = f"{temp_folder}/{truncated_text}_{random_string}.wav"
         | 
| 354 | 
             
                return file_name
         | 
| 355 | 
            +
             | 
