-
Notifications
You must be signed in to change notification settings - Fork 471
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
Use socket send async func to wrap the various socket send function w… #911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,9 @@ def stream_audio(audio_buffer): | |
) | ||
|
||
print(f'deepgram-obns3: send_initial_file_path > deepgram_socket {deepgram_socket}') | ||
await send_initial_file_path(file_path, deepgram_socket) | ||
async def deepgram_socket_send(data): | ||
return deepgram_socket.send(data) | ||
await send_initial_file_path(file_path, deepgram_socket_send) | ||
# SONIOX | ||
elif stt_service == STTService.soniox: | ||
soniox_socket = await process_audio_soniox( | ||
|
@@ -231,7 +233,7 @@ def stream_audio(audio_buffer): | |
stream_transcript, speech_profile_stream_id, sample_rate, language, preseconds=duration | ||
) | ||
if duration: | ||
await send_initial_file_path(file_path, speechmatics_socket) | ||
await send_initial_file_path(file_path, speechmatics_socket.send) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, the change from directly using the - await send_initial_file_path(file_path, speechmatics_socket.send)
+ await send_initial_file_path(file_path, speechmatics_socket) |
||
print('speech_profile speechmatics duration', duration) | ||
|
||
except Exception as e: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from typing import List | ||
|
||
import websockets | ||
from deepgram import DeepgramClient, DeepgramClientOptions, LiveTranscriptionEvents | ||
from deepgram import DeepgramClient, DeepgramClientOptions, LiveTranscriptionEvents, ListenWebSocketClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import statement has been modified to include - from deepgram import DeepgramClient, DeepgramClientOptions, LiveTranscriptionEvents, ListenWebSocketClient
+ from deepgram import DeepgramClient, DeepgramClientOptions, LiveTranscriptionEvents |
||
from deepgram.clients.live.v1 import LiveOptions | ||
|
||
import database.notifications as notification_db | ||
|
@@ -61,7 +61,7 @@ | |
# return segments | ||
|
||
|
||
async def send_initial_file_path(file_path: str, transcript_socket): | ||
async def send_initial_file_path(file_path: str, transcript_socket_async_send): | ||
print('send_initial_file_path') | ||
start = time.time() | ||
# Reading and sending in chunks | ||
|
@@ -71,7 +71,7 @@ async def send_initial_file_path(file_path: str, transcript_socket): | |
if not chunk: | ||
break | ||
# print('Uploading', len(chunk)) | ||
await transcript_socket.send(bytes(chunk)) | ||
await transcript_socket_async_send(bytes(chunk)) | ||
await asyncio.sleep(0.0001) # if it takes too long to transcribe | ||
|
||
print('send_initial_file_path', time.time() - start) | ||
|
@@ -154,9 +154,39 @@ def process_segments(uid: str, segments: list[dict]): | |
def connect_to_deepgram(on_message, on_error, language: str, sample_rate: int, channels: int): | ||
# 'wss://api.deepgram.com/v1/listen?encoding=linear16&sample_rate=8000&language=$recordingsLanguage&model=nova-2-general&no_delay=true&endpointing=100&interim_results=false&smart_format=true&diarize=true' | ||
try: | ||
dg_connection = deepgram.listen.live.v("1") | ||
dg_connection = deepgram.listen.websocket.v("1") | ||
dg_connection.on(LiveTranscriptionEvents.Transcript, on_message) | ||
dg_connection.on(LiveTranscriptionEvents.Error, on_error) | ||
|
||
def on_open(self, open, **kwargs): | ||
print("Connection Open") | ||
|
||
def on_metadata(self, metadata, **kwargs): | ||
print(f"Metadata: {metadata}") | ||
|
||
def on_speech_started(self, speech_started, **kwargs): | ||
print("Speech Started") | ||
|
||
def on_utterance_end(self, utterance_end, **kwargs): | ||
print("Utterance End") | ||
global is_finals | ||
if len(is_finals) > 0: | ||
utterance = " ".join(is_finals) | ||
print(f"Utterance End: {utterance}") | ||
is_finals = [] | ||
|
||
def on_close(self, close, **kwargs): | ||
print("Connection Closed") | ||
|
||
def on_unhandled(self, unhandled, **kwargs): | ||
print(f"Unhandled Websocket Message: {unhandled}") | ||
|
||
dg_connection.on(LiveTranscriptionEvents.Open, on_open) | ||
dg_connection.on(LiveTranscriptionEvents.Metadata, on_metadata) | ||
dg_connection.on(LiveTranscriptionEvents.SpeechStarted, on_speech_started) | ||
dg_connection.on(LiveTranscriptionEvents.UtteranceEnd, on_utterance_end) | ||
dg_connection.on(LiveTranscriptionEvents.Close, on_close) | ||
dg_connection.on(LiveTranscriptionEvents.Unhandled, on_unhandled) | ||
Comment on lines
+157
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The event handling functions Also, the variable Here's a possible fix: remove the - def on_open(self, open, **kwargs):
+ def on_open(open, **kwargs):
print("Connection Open")
- def on_metadata(self, metadata, **kwargs):
+ def on_metadata(metadata, **kwargs):
print(f"Metadata: {metadata}")
- def on_speech_started(self, speech_started, **kwargs):
+ def on_speech_started(speech_started, **kwargs):
print("Speech Started")
- def on_utterance_end(self, utterance_end, **kwargs):
+ def on_utterance_end(utterance_end, **kwargs):
print("Utterance End")
+ is_finals = []
if len(is_finals) > 0:
utterance = " ".join(is_finals)
print(f"Utterance End: {utterance}")
is_finals = []
- def on_close(self, close, **kwargs):
+ def on_close(close, **kwargs):
print("Connection Closed")
- def on_unhandled(self, unhandled, **kwargs):
+ def on_unhandled(unhandled, **kwargs):
print(f"Unhandled Websocket Message: {unhandled}") |
||
options = LiveOptions( | ||
punctuate=True, | ||
no_delay=True, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entelligence.AI
The change from directly using the
deepgram_socket
to send data to wrapping it in a new functiondeepgram_socket_send
seems unnecessary. Thesend_initial_file_path
function is now expecting a function instead of a socket object, which could lead to confusion for future developers. If there's a specific reason for this change, consider adding comments to clarify.