Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model size option #76

Merged
merged 10 commits into from
Dec 20, 2023
Merged
1 change: 1 addition & 0 deletions Audio-Transcription-Chrome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ When using the Audio Transcription extension, you have the following options:
- **Use Multilingual Model**: Enable this option to utilize the multilingual capabilities of OpenAI-whisper.
- **Language**: Select the target language for transcription or translation. You can choose from a variety of languages supported by OpenAI-whisper.
- **Task:** Choose the specific task to perform on the audio. You can select either "transcribe" for transcription or "translate" to translate the audio to English.
- **Model Size**: Select the whisper model size to run the server with.

### Getting Started
- Make sure the transcription server is running properly. To know more about how to start the server, see the [documentation here](https://github.com/collabora/whisper-live).
Expand Down
3 changes: 2 additions & 1 deletion Audio-Transcription-Chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ async function startCapture(options) {
port: options.port,
multilingual: options.useMultilingual,
language: options.language,
task: options.task
task: options.task,
modelSize: options.modelSize
},
});
} else {
Expand Down
3 changes: 2 additions & 1 deletion Audio-Transcription-Chrome/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ async function startRecord(option) {
uid: uuid,
multilingual: option.multilingual,
language: option.language,
task: option.task
task: option.task,
model_size: option.modelSize
})
);
};
Expand Down
13 changes: 12 additions & 1 deletion Audio-Transcription-Chrome/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,22 @@
</div>
<div class="dropdown-container">
<label for="taskDropdown">Select task:</label>
<select id="taskDropdown" disabled>
<select id="taskDropdown" >
<option value="">Select Task</option>
<option value="transcribe" selected>Transcribe</option>
<option value="translate">Translate</option>
</select>
</div>
<div class="dropdown-container">
<label for="modelSizeDropdown">Select Model Size:</label>
<select id="modelSizeDropdown">
<option value="">Select Task</option>
<option value="tiny">Tiny</option>
<option value="base">Base</option>
<option value="small" selected>Small</option>
<option value="medium">Medium</option>
<option value="large-v2">Large-v2</option>
</select>
</div>
</body>
</html>
20 changes: 18 additions & 2 deletions Audio-Transcription-Chrome/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ document.addEventListener("DOMContentLoaded", function () {
const useMultilingualCheckbox = document.getElementById('useMultilingualCheckbox');
const languageDropdown = document.getElementById('languageDropdown');
const taskDropdown = document.getElementById('taskDropdown');
const modelSizeDropdown = document.getElementById('modelSizeDropdown');
let selectedLanguage = null;
let selectedTask = taskDropdown.value;
let selectedModelSize = modelSizeDropdown.value;

// Add click event listeners to the buttons
startButton.addEventListener("click", startCapture);
Expand Down Expand Up @@ -52,6 +54,13 @@ document.addEventListener("DOMContentLoaded", function () {
}
});

chrome.storage.local.get("selectedModelSize", ({ selectedModelSize: storedModelSize }) => {
if (storedModelSize !== undefined) {
modelSizeDropdown.value = storedModelSize;
selectedModelSize = storedModelSize;
}
});

// Function to handle the start capture button click event
async function startCapture() {
// Ignore click if the button is disabled
Expand All @@ -64,7 +73,7 @@ document.addEventListener("DOMContentLoaded", function () {

// Send a message to the background script to start capturing
let host = "localhost";
let port = "9090";
let port = "5901";
const useCollaboraServer = useServerCheckbox.checked;
if (useCollaboraServer){
host = "transcription.kurg.org"
Expand All @@ -79,7 +88,8 @@ document.addEventListener("DOMContentLoaded", function () {
port: port,
useMultilingual: useMultilingualCheckbox.checked,
language: selectedLanguage,
task: selectedTask
task: selectedTask,
modelSize: selectedModelSize
}, () => {
// Update capturing state in storage and toggle the buttons
chrome.storage.local.set({ capturingState: { isCapturing: true } }, () => {
Expand Down Expand Up @@ -120,6 +130,7 @@ document.addEventListener("DOMContentLoaded", function () {
stopButton.disabled = !isCapturing;
useServerCheckbox.disabled = isCapturing;
useMultilingualCheckbox.disabled = isCapturing;
modelSizeDropdown.disabled = isCapturing;

startButton.classList.toggle("disabled", isCapturing);
stopButton.classList.toggle("disabled", !isCapturing);
Expand Down Expand Up @@ -157,6 +168,11 @@ document.addEventListener("DOMContentLoaded", function () {
chrome.storage.local.set({ selectedTask });
});

modelSizeDropdown.addEventListener('change', function() {
selectedModelSize = modelSizeDropdown.value;
chrome.storage.local.set({ selectedModelSize });
});

chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
if (request.action === "updateSelectedLanguage") {
const detectedLanguage = request.detectedLanguage;
Expand Down
1 change: 1 addition & 0 deletions Audio-Transcription-Firefox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ When using the Audio Transcription extension, you have the following options:
- **Use Multilingual Model**: Enable this option to utilize the multilingual capabilities of OpenAI-whisper.
- **Language**: Select the target language for transcription or translation. You can choose from a variety of languages supported by OpenAI-whisper.
- **Task:** Choose the specific task to perform on the audio. You can select either "transcribe" for transcription or "translate" to translate the audio to English.
- **Model Size**: Select the whisper model size to run the server with.

### Getting Started
- Make sure the transcription server is running properly. To know more about how to start the server, see the [documentation here](https://github.com/collabora/whisper-live).
Expand Down
3 changes: 2 additions & 1 deletion Audio-Transcription-Firefox/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function startRecording(data) {
uid: uuid,
multilingual: data.useMultilingual,
language: data.language,
task: data.task
task: data.task,
model_size: data.modelSize
})
);
};
Expand Down
11 changes: 11 additions & 0 deletions Audio-Transcription-Firefox/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,16 @@
<option value="translate">Translate</option>
</select>
</div>
<div class="dropdown-container">
<label for="modelSizeDropdown">Select Model Size:</label>
<select id="modelSizeDropdown">
<option value="">Select Task</option>
<option value="tiny">Tiny</option>
<option value="base">Base</option>
<option value="small" selected>Small</option>
<option value="medium">Medium</option>
<option value="large-v2">Large-v2</option>
</select>
</div>
</body>
</html>
21 changes: 19 additions & 2 deletions Audio-Transcription-Firefox/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ document.addEventListener("DOMContentLoaded", function() {
const useMultilingualCheckbox = document.getElementById('useMultilingualCheckbox');
const languageDropdown = document.getElementById('languageDropdown');
const taskDropdown = document.getElementById('taskDropdown');
const modelSizeDropdown = document.getElementById('modelSizeDropdown');
let selectedLanguage = null;
let selectedTask = taskDropdown.value;
let selectedModelSize = modelSizeDropdown.value;


browser.storage.local.get("capturingState")
.then(function(result) {
Expand Down Expand Up @@ -54,9 +57,16 @@ document.addEventListener("DOMContentLoaded", function() {
}
});

browser.storage.local.get("selectedModelSize", ({ selectedModelSize: storedModelSize }) => {
if (storedModelSize !== undefined) {
modelSizeDropdown.value = storedModelSize;
selectedModelSize = storedModelSize;
}
});

startButton.addEventListener("click", function() {
let host = "localhost";
let port = "9090";
let port = "5901";
const useCollaboraServer = useServerCheckbox.checked;

if (useCollaboraServer){
Expand All @@ -75,7 +85,8 @@ document.addEventListener("DOMContentLoaded", function() {
port: port,
useMultilingual: useMultilingualCheckbox.checked,
language: selectedLanguage,
task: selectedTask
task: selectedTask,
modelSize: selectedModelSize
}
});
toggleCaptureButtons(true);
Expand Down Expand Up @@ -115,6 +126,7 @@ document.addEventListener("DOMContentLoaded", function() {
stopButton.disabled = !isCapturing;
useServerCheckbox.disabled = isCapturing;
useMultilingualCheckbox.disabled = isCapturing;
modelSizeDropdown.disabled = isCapturing;

startButton.classList.toggle("disabled", isCapturing);
stopButton.classList.toggle("disabled", !isCapturing);
Expand Down Expand Up @@ -152,6 +164,11 @@ document.addEventListener("DOMContentLoaded", function() {
browser.storage.local.set({ selectedTask });
});

modelSizeDropdown.addEventListener('change', function() {
selectedModelSize = modelSizeDropdown.value;
browser.storage.local.set({ selectedModelSize });
});

browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "updateSelectedLanguage") {
const detectedLanguage = request.data;
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,33 @@ Unlike traditional speech recognition systems that rely on continuous audio stre
- To transcribe an audio file:
```python
from whisper_live.client import TranscriptionClient
client = TranscriptionClient("localhost", 9090, is_multilingual=True, lang="hi", translate=True)
client(audio_file_path)
client = TranscriptionClient(
"localhost",
9090,
is_multilingual=False,
lang="en",
translate=False,
model_size="small"
)

client("tests/jfk.wav")
```
This command transcribes the specified audio file (audio.wav) using the Whisper model. It connects to the server running on localhost at port 9090. It also enables the multilingual feature, allowing transcription in multiple languages. The language option specifies the target language for transcription, in this case, Hindi ("hi"). The translate option should be set to `True` if we want to translate from the source language to English and `False` if we want to transcribe in the source language.
This command transcribes the specified audio file (audio.wav) using the Whisper model. It connects to the server running on localhost at port 9090. It can also enable the multilingual feature, allowing transcription in multiple languages. The language option specifies the target language for transcription, in this case, English ("en"). The translate option should be set to `True` if we want to translate from the source language to English and `False` if we want to transcribe in the source language.

- To transcribe from microphone:
```python
from whisper_live.client import TranscriptionClient
client = TranscriptionClient(host, port, is_multilingual=True, lang="hi", translate=True)
client = TranscriptionClient(
"localhost",
9090,
is_multilingual=True,
lang="hi",
translate=True,
model_size="small"
)
client()
```
This command captures audio from the microphone and sends it to the server for transcription. It uses the same options as the previous command, enabling the multilingual feature and specifying the target language and task.
This command captures audio from the microphone and sends it to the server for transcription. It uses the multilingual option with `hi` as the selectelanguage, enabling the multilingual feature and specifying the target language and task. We use whisper `small` by default but can be changed to any other option based on the requirements and the hardware running the server.

- To trasncribe from a HLS stream:
```python
Expand Down
Binary file added tests/jfk.flac
Binary file not shown.
30 changes: 19 additions & 11 deletions whisper_live/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Client:
INSTANCES = {}

def __init__(
self, host=None, port=None, is_multilingual=False, lang=None, translate=False
self, host=None, port=None, is_multilingual=False, lang=None, translate=False, model_size="small"
):
"""
Initializes a Client instance for audio recording and streaming to a server.
Expand Down Expand Up @@ -80,7 +80,9 @@ def __init__(
self.last_response_recieved = None
self.disconnect_if_no_response_for = 15
self.multilingual = is_multilingual
self.language = lang if is_multilingual else "en"
self.language = lang
self.model_size = model_size
self.server_error = False
if translate:
self.task = "translate"

Expand Down Expand Up @@ -140,11 +142,16 @@ def on_message(self, ws, message):
print("[ERROR]: invalid client uid")
return

if "status" in message.keys() and message["status"] == "WAIT":
self.waiting = True
print(
f"[INFO]:Server is full. Estimated wait time {round(message['message'])} minutes."
)
if "status" in message.keys():
if message["status"] == "WAIT":
self.waiting = True
print(
f"[INFO]:Server is full. Estimated wait time {round(message['message'])} minutes."
)
elif message["status"] == "ERROR":
print(f"Message from Server: {message['message']}")
self.server_error = True
return

if "message" in message.keys() and message["message"] == "DISCONNECT":
print("[INFO]: Server overtime disconnected.")
Expand Down Expand Up @@ -213,6 +220,7 @@ def on_open(self, ws):
"multilingual": self.multilingual,
"language": self.language,
"task": self.task,
"model_size": self.model_size,
}
)
)
Expand Down Expand Up @@ -497,8 +505,8 @@ class TranscriptionClient:
transcription_client()
```
"""
def __init__(self, host, port, is_multilingual=False, lang=None, translate=False):
self.client = Client(host, port, is_multilingual, lang, translate)
def __init__(self, host, port, is_multilingual=False, lang=None, translate=False, model_size="small"):
self.client = Client(host, port, is_multilingual, lang, translate, model_size)

def __call__(self, audio=None, hls_url=None):
"""
Expand All @@ -514,10 +522,10 @@ def __call__(self, audio=None, hls_url=None):
"""
print("[INFO]: Waiting for server ready ...")
while not self.client.recording:
if self.client.waiting:
if self.client.waiting or self.client.server_error:
self.client.close_websocket()
return
pass

print("[INFO]: Server Ready!")
if hls_url is not None:
self.client.process_hls_stream(hls_url)
Expand Down
Loading
Loading