Skip to content

Commit

Permalink
use config.ini instead of json file
Browse files Browse the repository at this point in the history
  • Loading branch information
vonhathanh committed Oct 20, 2024
1 parent 37c5027 commit b7e8884
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[DEFAULT]
model = base.en
threshold = 200

18 changes: 8 additions & 10 deletions flow/configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import pyaudio
import configparser

from enum import Enum

Expand All @@ -11,6 +12,10 @@ class AppStatus(str, Enum):
STOPPED = "App stopped"
CLOSING = "Closing app..."

CONFIG_FILE = "./config.ini"

config = configparser.ConfigParser()
config.read(CONFIG_FILE)

# Audio parameters
CHUNK = 1024
Expand All @@ -19,22 +24,15 @@ class AppStatus(str, Enum):
RATE = 44100

# Voice Activity Detection parameters
THRESHOLD = int(os.getenv("THRESHOLD", "200")) # Adjust this value based on your microphone and environment
THRESHOLD = int(config["DEFAULT"]["threshold"]) # Adjust this value based on your microphone and environment
SILENCE_LIMIT = 0.5 # Number of seconds of silence to stop the recording

IGNORED_WORDS = {"", " "}

# directory to store the audio files
RECORDINGS_DIR = "./recordings/"

CONFIG_FILE = "./config.json"

AVAILABLE_MODELS = ["tiny.en", "base.en", "small.en", "medium.en", "large", "turbo"]

if not os.path.exists(CONFIG_FILE):
with open(CONFIG_FILE, "w+") as f:
json.dump({"model": "tiny.en"}, f)

with open(CONFIG_FILE, "r") as f:
# default whisper model
CURRENT_MODEL = json.load(f)["model"]
# default whisper model
CURRENT_MODEL = config["DEFAULT"]["model"]
5 changes: 4 additions & 1 deletion flow/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def record_audio(message_queue: Queue):
stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
except OSError:
message_queue.put("Invalid input device")
return


audio_buffer = []
Expand Down Expand Up @@ -175,8 +176,10 @@ def reload_model(self):
self.model_loading_process = Process(target=reload_model, args=(model_name, self.message_queue))
self.model_loading_process.start()

config["DEFAULT"]["model"] = model_name

with open(CONFIG_FILE, "w") as f:
json.dump({"model": model_name}, f)
config.write(f)

def start_processes(self):
self.record_process = multiprocessing.Process(target=record_audio, args=(self.message_queue,))
Expand Down

0 comments on commit b7e8884

Please sign in to comment.