-
Notifications
You must be signed in to change notification settings - Fork 38
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
example with valid return #57
Comments
Hi! First, you can introduce a variable field named asr_result to this inherited class by overriding the init function, and update its value in the loop. class MyEventHandler(TranscriptResultStreamHandler):
def __init__(self, transcript_result_stream: TranscriptResultStream):
super().__init__(transcript_result_stream)
self.asr_result = ""
async def handle_transcript_event(self, transcript_event: TranscriptEvent):
# This handler can be implemented to handle transcriptions as needed.
# Here's an example to get started.
results = transcript_event.transcript.results
for result in results:
for alt in result.alternatives:
self.asr_result = alt.transcript
print(alt.transcript) Next, in the end of the basic_transcribe function, return the asr_result value of the handler object. # Instantiate our handler and start processing events
handler = MyEventHandler(stream.output_stream)
await asyncio.gather(write_chunks(), handler.handle_events())
return handler.asr_result Finally, when using asyncio, create a task and return the result of the task. def amazon(audio_path, language, region):
loop = asyncio.get_event_loop()
task = loop.create_task(basic_transcribe(audio_path, language, region))
# loop.run_until_complete(basic_transcribe(audio_path, language, region))
loop.run_until_complete(task)
loop.close()
return task.result() |
Hello. I'm new to Python programming and I'm having a little trouble making the correct adjustments to these examples. In my case I am using the example to capture audio by microphone and I would like to have the return only of the last line of final transcription and not of all the alternatives. I know that the last answer explained how to do it. But it doesn't seem to work with my example file. import asyncio from amazon_transcribe.client import TranscribeStreamingClient class MyEventHandler(TranscriptResultStreamHandler): async def mic_stream():
async def write_chunks(stream): async def basic_transcribe():
loop = asyncio.get_event_loop() |
i have used your way but i got only the last sentence result. how can i get the intermediate result and final result? |
Can you please provide another clear example of a streaming transcription that has a
return
. At present, the return ofalt.transcript
when reaching it's final state (i.e.not is_partial
) results a [None, None]. Example code as modified:The text was updated successfully, but these errors were encountered: