How Can I use the output of recognized speech to implement into PyWebIo (WebApp framework ) (using put(text))

192 views Asked by At

I am developing a webApp using PyWebio which is basically a speech translation/transcription tool.

I created the main outlay which looks basically this:

Main Page Design

Here, I used the put_scrollable function to create a text box

put_markdown("Transcript")
    put_scrollable(put_scope('transcriptpage'), height=200, keep_bottom=True)
    put_text(**"Speech Translation Results should come here"**, scope='transcriptpage')
    put_button("START RECOGNITION", onclick=partial(translation_continuous), color='info', outline=True)

I have created a scrollable section with a scope and on the bottom, there is a button which has the 'onclick' callback function binding to the actual speech recognition function (def).

Here's my speech recognizer function source code within a def:

def translation_continuous():
    # <TranslationContinuous>
    translation_config = speechsdk.translation.SpeechTranslationConfig(
        subscription=speech_key, region=service_region,
        speech_recognition_language='tr-TR',
        target_languages=('en',), voice_name="de-DE-Hedda")
    audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)

    # Creates a translation recognizer using and audio file as input.
    recognizer = speechsdk.translation.TranslationRecognizer(
        translation_config=translation_config, audio_config=audio_config)
     recognizer.recognized.connect(lambda evt: print('\n {}'.format(evt.result.translations['en'])))

    recognizer.start_continuous_recognition()

The last line indicates the code which connects callback functions to the events fired by the recognizer (which is essential for event signal)

HERE'S WHAT I WANT:

I want to display the speech recognition results (e.g print(evt.result.translations['tr']) on the scrollable area once i click on the button.

As i wrote earlier, the onclick on the button calls the main function (translation_continous()) however, i am seeing the main results displayed on the terminal, not on the scrollable area on the app. So, I need a code to call the print function in a way that put_text("content")can real time display on the scrollable text box.

0

There are 0 answers