简体   繁体   中英

Is it possible to capture the text output of an Android google-voice-typing from terminal?

Say i want to use the microphone of my smartphone to input text in my terminal, using the google voice2speech engine. How would i do?

I would first listen to the output of google-voice-typing , (but how?) and then redirect to stdin .

Is there a simple way with adb commands?

You can use AndroidViewClient/culebra to

  1. find the Google quick search box
  2. click on the mic icon
  3. prompt the user to say something
  4. find the search results
  5. print the text
#! /usr/bin/env python3


from com.dtmilano.android.viewclient import ViewClient

helper = ViewClient.view_client_helper()

# mic in voice search widget
obj_ref = helper.until.find_object(body={
    'clazz': 'android.widget.ImageButton',
    'clickable': True,
    'desc': 'Voice Search'
})
response = helper.ui_device.wait(oid=obj_ref.oid)
helper.ui_object2.click(oid=response['oid'])
print('Speak now...')
helper.ui_device.wait_for_window_update()

# text in search results
obj_ref = helper.until.find_object(body={
    'res': 'com.google.android.googlequicksearchbox:id/googleapp_srp_search_box_text',
    'clazz': 'android.widget.TextView'
})
response = helper.ui_device.wait(oid=obj_ref.oid)
print('Text:')
print(helper.ui_object2.get_text(oid=response['oid']).text)

The output would be like this

Speak now...
Text:
this is another example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM