Merge branch 'main' into fix/tts-install-mac-asset-url-unboundlocalerror

pull/175/head
Ty Fiero 10 months ago committed by GitHub
commit 5f35f68b4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -12,6 +12,8 @@ import subprocess
import os
import subprocess
import platform
import urllib.request
class Stt:
@ -23,7 +25,6 @@ class Stt:
return stt(self.service_directory, audio_file_path)
def install(service_dir):
### INSTALL
@ -42,13 +43,15 @@ def install(service_dir):
# Check if whisper-rust executable exists before attempting to build
if not os.path.isfile(os.path.join(WHISPER_RUST_PATH, "target/release/whisper-rust")):
# Check if Rust is installed. Needed to build whisper executable
rust_check = subprocess.call('command -v rustc', shell=True)
if rust_check != 0:
rustc_path = shutil.which("rustc")
if rustc_path is None:
print("Rust is not installed or is not in system PATH. Please install Rust before proceeding.")
exit(1)
# Build Whisper Rust executable if not found
subprocess.call('cargo build --release', shell=True)
subprocess.run(['cargo', 'build', '--release'], check=True)
else:
print("Whisper Rust executable already exists. Skipping build.")
@ -59,10 +62,12 @@ def install(service_dir):
if not os.path.isfile(os.path.join(WHISPER_MODEL_PATH, WHISPER_MODEL_NAME)):
os.makedirs(WHISPER_MODEL_PATH, exist_ok=True)
subprocess.call(f'curl -L "{WHISPER_MODEL_URL}{WHISPER_MODEL_NAME}" -o "{os.path.join(WHISPER_MODEL_PATH, WHISPER_MODEL_NAME)}"', shell=True)
urllib.request.urlretrieve(f"{WHISPER_MODEL_URL}{WHISPER_MODEL_NAME}",
os.path.join(WHISPER_MODEL_PATH, WHISPER_MODEL_NAME))
else:
print("Whisper model already exists. Skipping download.")
def convert_mime_type_to_format(mime_type: str) -> str:
if mime_type == "audio/x-wav" or mime_type == "audio/wav":
return "wav"
@ -73,6 +78,7 @@ def convert_mime_type_to_format(mime_type: str) -> str:
return mime_type
@contextlib.contextmanager
def export_audio_to_wav_ffmpeg(audio: bytearray, mime_type: str) -> str:
temp_dir = tempfile.gettempdir()
@ -105,10 +111,12 @@ def export_audio_to_wav_ffmpeg(audio: bytearray, mime_type: str) -> str:
os.remove(input_path)
os.remove(output_path)
def run_command(command):
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
return result.stdout, result.stderr
def get_transcription_file(service_directory, wav_file_path: str):
local_path = os.path.join(service_directory, 'model')
whisper_rust_path = os.path.join(service_directory, 'whisper-rust', 'target', 'release')
@ -124,14 +132,15 @@ def get_transcription_file(service_directory, wav_file_path: str):
def stt_wav(service_directory, wav_file_path: str):
temp_dir = tempfile.gettempdir()
output_path = os.path.join(temp_dir, f"output_stt_{datetime.now().strftime('%Y%m%d%H%M%S%f')}.wav")
ffmpeg.input(wav_file_path).output(output_path, acodec='pcm_s16le', ac=1, ar='16k').run()
try:
transcript = get_transcription_file(service_directory, output_path)
finally:
os.remove(output_path)
return transcript
temp_dir = tempfile.gettempdir()
output_path = os.path.join(temp_dir, f"output_stt_{datetime.now().strftime('%Y%m%d%H%M%S%f')}.wav")
ffmpeg.input(wav_file_path).output(output_path, acodec='pcm_s16le', ac=1, ar='16k').run()
try:
transcript = get_transcription_file(service_directory, output_path)
finally:
os.remove(output_path)
return transcript
def stt(service_directory, input_data):
return stt_wav(service_directory, input_data)

@ -49,7 +49,7 @@ class Tts:
return
elif OS == "windows":
if ARCH == "AMD64":
ARCH = "x64"
ARCH = "amd64"
else:
print("Piper: unsupported architecture")
return
@ -60,13 +60,14 @@ class Tts:
asset_url = f"{PIPER_URL}{PIPER_ASSETNAME}"
if OS == "windows":
asset_url = asset_url.replace(".tar.gz", ".zip")
# Download and extract Piper
urllib.request.urlretrieve(asset_url, os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME))
# Extract the downloaded file
if OS == "windows":
if OS == "Windows":
import zipfile
with zipfile.ZipFile(os.path.join(PIPER_FOLDER_PATH, PIPER_ASSETNAME), 'r') as zip_ref:
zip_ref.extractall(path=PIPER_FOLDER_PATH)

@ -45,6 +45,10 @@ last_messages = ""
def check_filtered_kernel():
messages = get_kernel_messages()
if messages is None:
return "" # Handle unsupported platform or error in fetching kernel messages
global last_messages
messages.replace(last_messages, "")
messages = messages.split("\n")
@ -55,6 +59,7 @@ def check_filtered_kernel():
return "\n".join(filtered_messages)
async def put_kernel_messages_into_queue(queue):
while True:
text = check_filtered_kernel()

Loading…
Cancel
Save