diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index d0c3cbf..0000000 --- a/docs/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Minimal makefile for Sphinx documentation -# - -# You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -SPHINXBUILD ?= sphinx-build -SOURCEDIR = source -BUILDDIR = build - -# Put it first so that "make" without argument is like "make help". -help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) - -.PHONY: help Makefile - -# Catch-all target: route all unknown targets to Sphinx using the new -# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). -%: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/doctrees/environment.pickle b/docs/doctrees/environment.pickle new file mode 100644 index 0000000..20a7ea1 Binary files /dev/null and b/docs/doctrees/environment.pickle differ diff --git a/docs/doctrees/index.doctree b/docs/doctrees/index.doctree new file mode 100644 index 0000000..5609183 Binary files /dev/null and b/docs/doctrees/index.doctree differ diff --git a/docs/html/.buildinfo b/docs/html/.buildinfo new file mode 100644 index 0000000..7598238 --- /dev/null +++ b/docs/html/.buildinfo @@ -0,0 +1,4 @@ +# Sphinx build info version 1 +# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. +config: 7b818b47e6f359b937e5a2517f120d43 +tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/_sources/index.rst.txt b/docs/html/_sources/index.rst.txt similarity index 100% rename from docs/_sources/index.rst.txt rename to docs/html/_sources/index.rst.txt diff --git a/docs/_static/alabaster.css b/docs/html/_static/alabaster.css similarity index 100% rename from docs/_static/alabaster.css rename to docs/html/_static/alabaster.css diff --git a/docs/_static/basic.css b/docs/html/_static/basic.css similarity index 100% rename from docs/_static/basic.css rename to docs/html/_static/basic.css diff --git a/docs/_static/custom.css b/docs/html/_static/custom.css similarity index 100% rename from docs/_static/custom.css rename to docs/html/_static/custom.css diff --git a/docs/_static/doctools.js b/docs/html/_static/doctools.js similarity index 100% rename from docs/_static/doctools.js rename to docs/html/_static/doctools.js diff --git a/docs/_static/documentation_options.js b/docs/html/_static/documentation_options.js similarity index 100% rename from docs/_static/documentation_options.js rename to docs/html/_static/documentation_options.js diff --git a/docs/_static/file.png b/docs/html/_static/file.png similarity index 100% rename from docs/_static/file.png rename to docs/html/_static/file.png diff --git a/docs/_static/language_data.js b/docs/html/_static/language_data.js similarity index 100% rename from docs/_static/language_data.js rename to docs/html/_static/language_data.js diff --git a/docs/_static/minus.png b/docs/html/_static/minus.png similarity index 100% rename from docs/_static/minus.png rename to docs/html/_static/minus.png diff --git a/docs/_static/plus.png b/docs/html/_static/plus.png similarity index 100% rename from docs/_static/plus.png rename to docs/html/_static/plus.png diff --git a/docs/_static/pygments.css b/docs/html/_static/pygments.css similarity index 100% rename from docs/_static/pygments.css rename to docs/html/_static/pygments.css diff --git a/docs/_static/searchtools.js b/docs/html/_static/searchtools.js similarity index 100% rename from docs/_static/searchtools.js rename to docs/html/_static/searchtools.js diff --git a/docs/_static/sphinx_highlight.js b/docs/html/_static/sphinx_highlight.js similarity index 100% rename from docs/_static/sphinx_highlight.js rename to docs/html/_static/sphinx_highlight.js diff --git a/docs/genindex.html b/docs/html/genindex.html similarity index 100% rename from docs/genindex.html rename to docs/html/genindex.html diff --git a/docs/html/index.html b/docs/html/index.html new file mode 100644 index 0000000..cd207e0 --- /dev/null +++ b/docs/html/index.html @@ -0,0 +1,295 @@ + + + + + + + + Welcome to whisper_live’s documentation! — whisper_live documentation + + + + + + + + + + + + + + + + +
+
+
+ + +
+ +
+

Welcome to whisper_live’s documentation!

+
+
+
+
+class whisper_live.server.ServeClient(websocket, task='transcribe', device=None, multilingual=False, language=None, client_uid=None)
+
+
Attributes:

RATE (int): The audio sampling rate (constant) set to 16000. +SERVER_READY (str): A constant message indicating that the server is ready. +DISCONNECT (str): A constant message indicating that the client should disconnect. +client_uid (str): A unique identifier for the client. +data (bytes): Accumulated audio data. +frames (bytes): Accumulated audio frames. +language (str): The language for transcription. +task (str): The task type, e.g., “transcribe.” +transcriber (WhisperModel): The Whisper model for speech-to-text. +timestamp_offset (float): The offset in audio timestamps. +frames_np (numpy.ndarray): NumPy array to store audio frames. +frames_offset (float): The offset in audio frames. +text (list): List of transcribed text segments. +current_out (str): The current incomplete transcription. +prev_out (str): The previous incomplete transcription. +t_start (float): Timestamp for the start of transcription. +exit (bool): A flag to exit the transcription thread. +same_output_threshold (int): Threshold for consecutive same output segments. +show_prev_out_thresh (int): Threshold for showing previous output segments. +add_pause_thresh (int): Threshold for adding a pause (blank) segment. +transcript (list): List of transcribed segments. +send_last_n_segments (int): Number of last segments to send to the client. +wrapper (textwrap.TextWrapper): Text wrapper for formatting text. +pick_previous_segments (int): Number of previous segments to include in the output. +websocket: The WebSocket connection for the client.

+
+
+
+
+add_frames(frame_np)
+

Add audio frames to the ongoing audio stream buffer.

+

This method is responsible for maintaining the audio stream buffer, allowing the continuous addition +of audio frames as they are received. It also ensures that the buffer does not exceed a specified size +to prevent excessive memory usage.

+

If the buffer size exceeds a threshold (45 seconds of audio data), it discards the oldest 30 seconds +of audio data to maintain a reasonable buffer size. If the buffer is empty, it initializes it with the provided +audio frame. The audio stream buffer is used for real-time processing of audio data for transcription.

+
+
Args:

frame_np (numpy.ndarray): The audio frame data as a NumPy array.

+
+
+
+ +
+
+cleanup()
+

Perform cleanup tasks before exiting the transcription service.

+

This method performs necessary cleanup tasks, including stopping the transcription thread, marking +the exit flag to indicate the transcription thread should exit gracefully, and destroying resources +associated with the transcription process.

+
+ +
+
+disconnect()
+

Notify the client of disconnection and send a disconnect message.

+

This method sends a disconnect message to the client via the WebSocket connection to notify them +that the transcription service is disconnecting gracefully.

+
+ +
+
+fill_output(output)
+

Format the current incomplete transcription output by combining it with previous complete segments. +The resulting transcription is wrapped into two lines, each containing a maximum of 50 characters.

+

It ensures that the combined transcription fits within two lines, with a maximum of 50 characters per line. +Segments are concatenated in the order they exist in the list of previous segments, with the most +recent complete segment first and older segments prepended as needed to maintain the character limit. +If a 3-second pause is detected in the previous segments, any text preceding it is discarded to ensure +the transcription starts with the most recent complete content. The resulting transcription is returned +as a single string.

+
+
Args:

output(str): The current incomplete transcription segment.

+
+
Returns:

str: A formatted transcription wrapped in two lines.

+
+
+
+ +
+
+speech_to_text()
+

Process an audio stream in an infinite loop, continuously transcribing the speech.

+

This method continuously receives audio frames, performs real-time transcription, and sends +transcribed segments to the client via a WebSocket connection.

+

If the client’s language is not detected, it waits for 30 seconds of audio input to make a language prediction. +It utilizes the Whisper ASR model to transcribe the audio, continuously processing and streaming results. Segments +are sent to the client in real-time, and a history of segments is maintained to provide context.Pauses in speech +(no output from Whisper) are handled by showing the previous output for a set duration. A blank segment is added if +there is no speech for a specified duration to indicate a pause.

+
+
Raises:

Exception: If there is an issue with audio processing or WebSocket communication.

+
+
+
+ +
+
+update_segments(segments, duration)
+

Processes the segments from whisper. Appends all the segments to the list +except for the last segment assuming that it is incomplete.

+

Updates the ongoing transcript with transcribed segments, including their start and end times. +Complete segments are appended to the transcript in chronological order. Incomplete segments +(assumed to be the last one) are processed to identify repeated content. If the same incomplete +segment is seen multiple times, it updates the offset and appends the segment to the transcript. +A threshold is used to detect repeated content and ensure it is only included once in the transcript. +The timestamp offset is updated based on the duration of processed segments. The method returns the +last processed segment, allowing it to be sent to the client for real-time updates.

+
+
Args:

segments(dict) : dictionary of segments as returned by whisper +duration(float): duration of the current chunk

+
+
Returns:
+
dict or None: The last processed segment with its start time, end time, and transcribed text.

Returns None if there are no valid segments to process.

+
+
+
+
+
+ +
+ +
+
+class whisper_live.server.TranscriptionServer
+

Represents a transcription server that handles incoming audio from clients.

+
+
Attributes:

RATE (int): The audio sampling rate (constant) set to 16000. +vad_model (torch.Module): The voice activity detection model. +vad_threshold (float): The voice activity detection threshold. +clients (dict): A dictionary to store connected clients. +websockets (dict): A dictionary to store WebSocket connections. +clients_start_time (dict): A dictionary to track client start times. +max_clients (int): Maximum allowed connected clients. +max_connection_time (int): Maximum allowed connection time in seconds.

+
+
+
+
+get_wait_time()
+

Calculate and return the estimated wait time for clients.

+
+
Returns:

float: The estimated wait time in minutes.

+
+
+
+ +
+
+recv_audio(websocket)
+

Receive audio chunks from a client in an infinite loop.

+

Continuously receives audio frames from a connected client +over a WebSocket connection. It processes the audio frames using a +voice activity detection (VAD) model to determine if they contain speech +or not. If the audio frame contains speech, it is added to the client’s +audio data for ASR. +If the maximum number of clients is reached, the method sends a +“WAIT” status to the client, indicating that they should wait +until a slot is available. +If a client’s connection exceeds the maximum allowed time, it will +be disconnected, and the client’s resources will be cleaned up.

+
+
Args:

websocket (WebSocket): The WebSocket connection for the client.

+
+
Raises:

Exception: If there is an error during the audio frame processing.

+
+
+
+ +
+
+run(host, port=9090)
+

Run the transcription server.

+
+
Args:

host (str): The host address to bind the server. +port (int): The port number to bind the server.

+
+
+
+ +
+ +
+
+

Indices and tables

+ +
+ + +
+ +
+
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/objects.inv b/docs/html/objects.inv similarity index 100% rename from docs/objects.inv rename to docs/html/objects.inv diff --git a/docs/py-modindex.html b/docs/html/py-modindex.html similarity index 100% rename from docs/py-modindex.html rename to docs/html/py-modindex.html diff --git a/docs/search.html b/docs/html/search.html similarity index 100% rename from docs/search.html rename to docs/html/search.html diff --git a/docs/searchindex.js b/docs/html/searchindex.js similarity index 100% rename from docs/searchindex.js rename to docs/html/searchindex.js diff --git a/docs/index.html b/docs/index.html index cd207e0..5896b1d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,295 +1 @@ - - - - - - - - Welcome to whisper_live’s documentation! — whisper_live documentation - - - - - - - - - - - - - - - - -
-
-
- - -
- -
-

Welcome to whisper_live’s documentation!

-
-
-
-
-class whisper_live.server.ServeClient(websocket, task='transcribe', device=None, multilingual=False, language=None, client_uid=None)
-
-
Attributes:

RATE (int): The audio sampling rate (constant) set to 16000. -SERVER_READY (str): A constant message indicating that the server is ready. -DISCONNECT (str): A constant message indicating that the client should disconnect. -client_uid (str): A unique identifier for the client. -data (bytes): Accumulated audio data. -frames (bytes): Accumulated audio frames. -language (str): The language for transcription. -task (str): The task type, e.g., “transcribe.” -transcriber (WhisperModel): The Whisper model for speech-to-text. -timestamp_offset (float): The offset in audio timestamps. -frames_np (numpy.ndarray): NumPy array to store audio frames. -frames_offset (float): The offset in audio frames. -text (list): List of transcribed text segments. -current_out (str): The current incomplete transcription. -prev_out (str): The previous incomplete transcription. -t_start (float): Timestamp for the start of transcription. -exit (bool): A flag to exit the transcription thread. -same_output_threshold (int): Threshold for consecutive same output segments. -show_prev_out_thresh (int): Threshold for showing previous output segments. -add_pause_thresh (int): Threshold for adding a pause (blank) segment. -transcript (list): List of transcribed segments. -send_last_n_segments (int): Number of last segments to send to the client. -wrapper (textwrap.TextWrapper): Text wrapper for formatting text. -pick_previous_segments (int): Number of previous segments to include in the output. -websocket: The WebSocket connection for the client.

-
-
-
-
-add_frames(frame_np)
-

Add audio frames to the ongoing audio stream buffer.

-

This method is responsible for maintaining the audio stream buffer, allowing the continuous addition -of audio frames as they are received. It also ensures that the buffer does not exceed a specified size -to prevent excessive memory usage.

-

If the buffer size exceeds a threshold (45 seconds of audio data), it discards the oldest 30 seconds -of audio data to maintain a reasonable buffer size. If the buffer is empty, it initializes it with the provided -audio frame. The audio stream buffer is used for real-time processing of audio data for transcription.

-
-
Args:

frame_np (numpy.ndarray): The audio frame data as a NumPy array.

-
-
-
- -
-
-cleanup()
-

Perform cleanup tasks before exiting the transcription service.

-

This method performs necessary cleanup tasks, including stopping the transcription thread, marking -the exit flag to indicate the transcription thread should exit gracefully, and destroying resources -associated with the transcription process.

-
- -
-
-disconnect()
-

Notify the client of disconnection and send a disconnect message.

-

This method sends a disconnect message to the client via the WebSocket connection to notify them -that the transcription service is disconnecting gracefully.

-
- -
-
-fill_output(output)
-

Format the current incomplete transcription output by combining it with previous complete segments. -The resulting transcription is wrapped into two lines, each containing a maximum of 50 characters.

-

It ensures that the combined transcription fits within two lines, with a maximum of 50 characters per line. -Segments are concatenated in the order they exist in the list of previous segments, with the most -recent complete segment first and older segments prepended as needed to maintain the character limit. -If a 3-second pause is detected in the previous segments, any text preceding it is discarded to ensure -the transcription starts with the most recent complete content. The resulting transcription is returned -as a single string.

-
-
Args:

output(str): The current incomplete transcription segment.

-
-
Returns:

str: A formatted transcription wrapped in two lines.

-
-
-
- -
-
-speech_to_text()
-

Process an audio stream in an infinite loop, continuously transcribing the speech.

-

This method continuously receives audio frames, performs real-time transcription, and sends -transcribed segments to the client via a WebSocket connection.

-

If the client’s language is not detected, it waits for 30 seconds of audio input to make a language prediction. -It utilizes the Whisper ASR model to transcribe the audio, continuously processing and streaming results. Segments -are sent to the client in real-time, and a history of segments is maintained to provide context.Pauses in speech -(no output from Whisper) are handled by showing the previous output for a set duration. A blank segment is added if -there is no speech for a specified duration to indicate a pause.

-
-
Raises:

Exception: If there is an issue with audio processing or WebSocket communication.

-
-
-
- -
-
-update_segments(segments, duration)
-

Processes the segments from whisper. Appends all the segments to the list -except for the last segment assuming that it is incomplete.

-

Updates the ongoing transcript with transcribed segments, including their start and end times. -Complete segments are appended to the transcript in chronological order. Incomplete segments -(assumed to be the last one) are processed to identify repeated content. If the same incomplete -segment is seen multiple times, it updates the offset and appends the segment to the transcript. -A threshold is used to detect repeated content and ensure it is only included once in the transcript. -The timestamp offset is updated based on the duration of processed segments. The method returns the -last processed segment, allowing it to be sent to the client for real-time updates.

-
-
Args:

segments(dict) : dictionary of segments as returned by whisper -duration(float): duration of the current chunk

-
-
Returns:
-
dict or None: The last processed segment with its start time, end time, and transcribed text.

Returns None if there are no valid segments to process.

-
-
-
-
-
- -
- -
-
-class whisper_live.server.TranscriptionServer
-

Represents a transcription server that handles incoming audio from clients.

-
-
Attributes:

RATE (int): The audio sampling rate (constant) set to 16000. -vad_model (torch.Module): The voice activity detection model. -vad_threshold (float): The voice activity detection threshold. -clients (dict): A dictionary to store connected clients. -websockets (dict): A dictionary to store WebSocket connections. -clients_start_time (dict): A dictionary to track client start times. -max_clients (int): Maximum allowed connected clients. -max_connection_time (int): Maximum allowed connection time in seconds.

-
-
-
-
-get_wait_time()
-

Calculate and return the estimated wait time for clients.

-
-
Returns:

float: The estimated wait time in minutes.

-
-
-
- -
-
-recv_audio(websocket)
-

Receive audio chunks from a client in an infinite loop.

-

Continuously receives audio frames from a connected client -over a WebSocket connection. It processes the audio frames using a -voice activity detection (VAD) model to determine if they contain speech -or not. If the audio frame contains speech, it is added to the client’s -audio data for ASR. -If the maximum number of clients is reached, the method sends a -“WAIT” status to the client, indicating that they should wait -until a slot is available. -If a client’s connection exceeds the maximum allowed time, it will -be disconnected, and the client’s resources will be cleaned up.

-
-
Args:

websocket (WebSocket): The WebSocket connection for the client.

-
-
Raises:

Exception: If there is an error during the audio frame processing.

-
-
-
- -
-
-run(host, port=9090)
-

Run the transcription server.

-
-
Args:

host (str): The host address to bind the server. -port (int): The port number to bind the server.

-
-
-
- -
- -
-
-

Indices and tables

- -
- - -
- -
-
- -
-
- - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/docs/make.bat b/docs/make.bat deleted file mode 100644 index 747ffb7..0000000 --- a/docs/make.bat +++ /dev/null @@ -1,35 +0,0 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=source -set BUILDDIR=build - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://www.sphinx-doc.org/ - exit /b 1 -) - -if "%1" == "" goto help - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd diff --git a/docs/source/conf.py b/docs/source/conf.py deleted file mode 100644 index f944f34..0000000 --- a/docs/source/conf.py +++ /dev/null @@ -1,36 +0,0 @@ -# Configuration file for the Sphinx documentation builder. -# -# For the full list of built-in configuration values, see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html - -# -- Project information ----------------------------------------------------- -# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -import os -import sys -sys.path.insert(0, os.path.abspath('../..')) - -project = 'whisper_live' -copyright = '2023, Collabora' -author = 'Collabora' - -# -- General configuration --------------------------------------------------- -# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration - -extensions = [] - -templates_path = ['_templates'] -exclude_patterns = [] - - - -# -- Options for HTML output ------------------------------------------------- -# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output - -html_theme = 'alabaster' -html_static_path = ['_static'] - -extensions = [ - 'sphinx.ext.duration', - 'sphinx.ext.doctest', - 'sphinx.ext.autodoc', -] diff --git a/docs/source/index.rst b/docs/source/index.rst deleted file mode 100644 index e57b0ad..0000000 --- a/docs/source/index.rst +++ /dev/null @@ -1,25 +0,0 @@ -.. whisper_live documentation master file, created by - sphinx-quickstart on Fri Sep 22 11:39:30 2023. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Welcome to whisper_live's documentation! -======================================== - -.. toctree:: - :maxdepth: 2 - - -.. automodule:: whisper_live.server - :members: - -.. automodule:: whisper_live.client - - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search`