mirror of
				https://github.com/cdryzun/tg_bot_collections.git
				synced 2025-11-04 16:56:43 +08:00 
			
		
		
		
	fix: lint
This commit is contained in:
		@ -16,18 +16,21 @@ if USE_CHATTTS:
 | 
				
			|||||||
    chat.load_models()
 | 
					    chat.load_models()
 | 
				
			||||||
    lock = threading.Lock()  # Initialize a lock
 | 
					    lock = threading.Lock()  # Initialize a lock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def generate_tts_wav(prompt):
 | 
					    def generate_tts_wav(prompt):
 | 
				
			||||||
        texts = [prompt,]
 | 
					        texts = [
 | 
				
			||||||
 | 
					            prompt,
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
        wavs = chat.infer(texts, use_decoder=True)
 | 
					        wavs = chat.infer(texts, use_decoder=True)
 | 
				
			||||||
        output_filename = 'tts.wav'
 | 
					        output_filename = "tts.wav"
 | 
				
			||||||
        audio_data = np.array(wavs[0], dtype=np.float32)  # Ensure the data type is correct
 | 
					        audio_data = np.array(
 | 
				
			||||||
 | 
					            wavs[0], dtype=np.float32
 | 
				
			||||||
 | 
					        )  # Ensure the data type is correct
 | 
				
			||||||
        sample_rate = 24000
 | 
					        sample_rate = 24000
 | 
				
			||||||
        # Normalize the audio data to 16-bit PCM range
 | 
					        # Normalize the audio data to 16-bit PCM range
 | 
				
			||||||
        audio_data = (audio_data * 32767).astype(np.int16)
 | 
					        audio_data = (audio_data * 32767).astype(np.int16)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Open a .wav file to write into
 | 
					        # Open a .wav file to write into
 | 
				
			||||||
        with wave.open(output_filename, 'w') as wf:
 | 
					        with wave.open(output_filename, "w") as wf:
 | 
				
			||||||
            wf.setnchannels(1)  # Mono channel
 | 
					            wf.setnchannels(1)  # Mono channel
 | 
				
			||||||
            wf.setsampwidth(2)  # 2 bytes per sample
 | 
					            wf.setsampwidth(2)  # 2 bytes per sample
 | 
				
			||||||
            wf.setframerate(sample_rate)
 | 
					            wf.setframerate(sample_rate)
 | 
				
			||||||
@ -35,12 +38,10 @@ if USE_CHATTTS:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        print(f"Audio has been saved to {output_filename}")
 | 
					        print(f"Audio has been saved to {output_filename}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def tts_handler(message: Message, bot: TeleBot):
 | 
					    def tts_handler(message: Message, bot: TeleBot):
 | 
				
			||||||
        """pretty tts: /tts <address>"""
 | 
					        """pretty tts: /tts <address>"""
 | 
				
			||||||
        bot.reply_to(
 | 
					        bot.reply_to(
 | 
				
			||||||
            message,
 | 
					            message, f"Generating ChatTTS may take some time please wait some time."
 | 
				
			||||||
            f"Generating ChatTTS may take some time please wait some time." 
 | 
					 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        m = message.text.strip()
 | 
					        m = message.text.strip()
 | 
				
			||||||
        prompt = m.strip()
 | 
					        prompt = m.strip()
 | 
				
			||||||
@ -58,8 +59,6 @@ if USE_CHATTTS:
 | 
				
			|||||||
            print(e)
 | 
					            print(e)
 | 
				
			||||||
            bot.reply_to(message, "tts error")
 | 
					            bot.reply_to(message, "tts error")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def register(bot: TeleBot) -> None:
 | 
					    def register(bot: TeleBot) -> None:
 | 
				
			||||||
        bot.register_message_handler(tts_handler, commands=["tts"], pass_bot=True)
 | 
					        bot.register_message_handler(tts_handler, commands=["tts"], pass_bot=True)
 | 
				
			||||||
        bot.register_message_handler(tts_handler, regexp="^tts:", pass_bot=True)
 | 
					        bot.register_message_handler(tts_handler, regexp="^tts:", pass_bot=True)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user