code: def sentence_to_wave(
      sentence,
      supported_languages,
      tts_speed,
      latent=None,
      return_as_byte=False,
      return_nonbyte_as_file=False,
      sr=24000,
      model=None,
      return_gradio=True,
      language="autodetect",
      verbose=False,
  ):
      """
      generate speech audio file per sentence
      """
      import noisereduce as nr
      import wave
  
      sentence = clean_sentence(sentence, verbose=verbose)
      sentence_list = [sentence]
  
      try:
          wav_bytestream = b""
          for sentence in sentence_list:
              if any(c.isalnum() for c in sentence):
                  if language == "autodetect":
                      # on first call autodetect, next sentence calls will use same language
                      language = detect_language(
                          sentence, supported_languages, verbose=verbose
                      )
  
                  # exists at least 1 alphanumeric (utf-8)
                  audio_stream = get_voice_streaming(
                      sentence,
                      language,
                      latent,
                      model=model,
                      tts_speed=tts_speed,
                  )
              else:
                  # likely got a ' or " or some other text without alphanumeric in it
                  audio_stream = None
  
              if audio_stream is not None:
                  frame_length = 0
                  for chunk in audio_stream:
                      try:
                          wav_bytestream += chunk
                          frame_length += len(chunk)
                      except Exception as e:
                          print(
                              "Exception in chunk appending: %s"
                              % str(e),
                              flush=True,
                          )
                          continue
  
              # Filter output for better voice
              filter_output = False
              if filter_output:
                  data_s16 = np.frombuffer(
                      wav_bytestream,
                      dtype=np.int16,
                      count=len(wav_bytestream) // 2,
                      offset=0,
                  )
                  float_data = data_s16 * 0.5**15
                  reduced_noise = nr.reduce_noise(
                      y=float_data, sr=sr, prop_decrease=0.8, n_fft=1024
                  )
                  wav_bytestream = (reduced_noise * 32767).astype(
                      np.int16
                  )
                  if return_as_byte:
                      wav_bytestream = wav_bytestream.tobytes()
  
              if audio_stream is not None:
                  if not return_as_byte:
                      if return_nonbyte_as_file:
                          tmpdir = os.getenv(
                              "TMPDDIR", tempfile.mkdtemp()
                          )
                          audio_unique_filename = os.path.join(
                              tmpdir, str(uuid.uuid4()) + ".wav"
                          )
                          with wave.open(
                              audio_unique_filename, "w"
                          ) as f:
                              f.setnchannels(1)
                              # 2 bytes per sample.
                              f.setsampwidth(2)
                              f.setframerate(sr)
                              f.writeframes(wav_bytestream)
  
                          ret_value = audio_unique_filename
                      else:
                          data_s16 = np.frombuffer(
                              wav_bytestream,
                              dtype=np.int16,
                              count=len(wav_bytestream) // 2,
                              offset=0,
                          )
                          float_data = data_s16 * 0.5**15
                          reduced_noise = nr.reduce_noise(
                              y=float_data,
                              sr=sr,
                              prop_decrease=0.8,
                              n_fft=1024,
                          )
                          wav_np = (reduced_noise * 32767).astype(
                              np.int16
                          )
                          ret_value = wav_np
                  else:
                      ret_value = wav_bytestream
                  if return_gradio:
                      import gradio as gr
  
                      return gr.Audio(value=ret_value, autoplay=True)
                  else:
                      return ret_value
      except RuntimeError as e:
          if "device-side assert" in str(e):
              print(
                  f"Restarted required due to exception: %s" % str(e),
                  flush=True,
              )
          else:
              print("Failed to generate wave: %s" % str(e))
              raise
  
imports: from __future__ import annotations
  import functools
  import io
  import os
  import tempfile
  import numpy
  import uuid
  import subprocess
  import time
  from src.tts_sentence_parsing import init_sentence_state, get_sentence, clean_sentence, detect_language
  from src.tts_utils import prepare_speech, get_no_audio, chunk_speed_change
  from src.utils import cuda_vis_check
  import torch
label_desc: Use image node_id 6 for calling a global function with example usage: sentence_to_wave(sentence, supported_languages, tts_speed, latent, return_as_byte, return_nonbyte_as_file, sr, model, return_gradio, language, verbose) and returns: gr, ret_value