Outdated realtime speaker identification example? #33
Unanswered
Frenzie
asked this question in
Community help & support
Replies: 1 comment
|
Quick POC with the new SDK: import asyncio
import os
from speechmatics.rt import (
AsyncClient,
ServerMessageType,
TranscriptionConfig,
TranscriptResult,
AudioFormat,
AudioEncoding,
)
async def main():
api_key = os.getenv("SPEECHMATICS_API_KEY")
audio_file = "speaker-identification-enrollment.wav"
client = AsyncClient(api_key=api_key)
@client.on(ServerMessageType.ADD_TRANSCRIPT)
def on_transcript(message):
print(f"[Transcript] {message}")
result = TranscriptResult.from_message(message)
for segment in result.segments:
speaker = segment.speaker or "Unknown"
text = segment.text
print(f"[Speaker {speaker}]: {text}")
@client.on(ServerMessageType.SPEAKERS_RESULT)
def on_speakers_result(message):
print(f"[SpeakersResult] {message}")
try:
with open(audio_file, "rb") as f:
await client.transcribe(
f,
transcription_config=TranscriptionConfig(
language="en",
diarization="speaker",
# Important, otherwise we don't get speaker IDs. Different default in speechmatics-rt vs speechmatics-python?
speaker_diarization_config={"get_speakers": True}
),
audio_format=AudioFormat(encoding=AudioEncoding.PCM_S16LE, sample_rate=16000),
)
finally:
await client.close()
asyncio.run(main()) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The example on https://docs.speechmatics.com/speech-to-text/realtime/speaker-identification seems to depend on things like
speechmatics.modelsandspeechmatics.client, which can only come fromspeechmatics-pythonif I'm not mistaken.But if you use that, you get:
Is the documentation outdated or should
speechmatics-pythonstill be used for speaker identification?All reactions