Skip to content

Commit

Permalink
fix azure stt language autodetection (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhao authored Dec 17, 2024
1 parent 891d5e7 commit c6e9fa8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-dragons-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-azure": patch
---

fix azure stt language autodetection
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def _create_speech_recognizer(
)

auto_detect_source_language_config = None
if config.languages and len(config.languages) > 1:
if config.languages and len(config.languages) >= 1:
auto_detect_source_language_config = (
speechsdk.languageconfig.AutoDetectSourceLanguageConfig(
languages=config.languages
Expand Down
11 changes: 10 additions & 1 deletion tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,37 @@ def reader():


def test_stream_buffer_large_chunks():
import hashlib

buffer = StreamBuffer()
large_chunk = b"x" * 1024 * 1024 # 1MB chunk
large_chunk = os.urandom(1024 * 1024) # 1MB of random bytes
num_chunks = 5
total_size = 0
write_completed = threading.Event()
input_hasher = hashlib.sha256()

def writer():
nonlocal total_size
for _ in range(num_chunks):
buffer.write(large_chunk)
total_size += len(large_chunk)
input_hasher.update(large_chunk)
buffer.end_input()
write_completed.set()

received_size = 0
output_hasher = hashlib.sha256()

def reader():
nonlocal received_size
# allow writer to start first
time.sleep(1)
while True:
chunk = buffer.read(8192) # Read in 8KB chunks
if not chunk:
break
received_size += len(chunk)
output_hasher.update(chunk)

# Run writer and reader in separate threads
with ThreadPoolExecutor(max_workers=2) as executor:
Expand All @@ -125,6 +133,7 @@ def reader():

assert received_size == total_size
assert total_size == num_chunks * len(large_chunk)
assert input_hasher.hexdigest() == output_hasher.hexdigest()


def test_stream_buffer_early_close():
Expand Down

0 comments on commit c6e9fa8

Please sign in to comment.