Skip to content
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

How to develop speech to text with Python in termux #95

Open
mandiladitya opened this issue Feb 12, 2020 · 4 comments
Open

How to develop speech to text with Python in termux #95

mandiladitya opened this issue Feb 12, 2020 · 4 comments

Comments

@mandiladitya
Copy link

I want to make speech to text with Python in termux so I used SpeechRecognition library of Python it installed correctly but it's can't get the record audio so is there any way or any changes I have to do to #access the microphones of phone using termux python

@mandiladitya mandiladitya changed the title How we maje speech to text with Python in termux How to develop speech to text with Python in termux Feb 12, 2020
@AbdullahM0hamed
Copy link
Contributor

You can do this using the termux-microphone-record script.

Something like the following:

import subprocess

def ensure_permission():
    no_permission_text = '''{
  "error": "Please grant the following permission to use this command: android.permission.RECORD_AUDIO"
}'''
    record = subprocess.getoutput("termux-microphone-record -d") 
    while record == no_permission_text:
        record = subprocess.getoutput("termux-microphone-record -d")

#This will start a recording if (or when) there is permission 
ensure_permission() 

#Call this when you want to finish the recording
recording = subprocess.getoutput("termux-microphone-record -q")[20:] 

@ashuhar455
Copy link

ashuhar455 commented Apr 23, 2020

Termux has a pkg called termux-api which includes termux-speech-to-text command that can be run from termux to record audio and directly convert it to text.

Install it using:

pkg install termux-api -y

To test, run:

termux-speech-to-text

There will be a beep after which you can speak and it gives output in text.

This can be used along with subprocess module within python to get the output and store it to a string.

import subprocess

inp = subprocess.getoutput("termux-speech-to-text")
print("You said: "+str(inp))

if inp == "Hello":
   print("Termux : Hello I am termux")

It uses Androids inbuit speech recognition feature with o ly downside that if you dont speak after the beep it will terminate with None as output.

Also, termux-tts-speak command can be utilised same way to turn the string into voice.
But it needs to be used with

os.system("termux-tts-speak {}".format(text_you_want_in_speech))

Assuming that os module is imported.

(Sorry for so many edits 😅)

@ashuhar455
Copy link

want to make speech to text with Python in termux so I used SpeechRecognition library of Python it installed correctly but it's can't get the record audio so is there any way or any changes I have to do to #access the microphones of phone using termux python

Talking about speech_recognition, termux doesnt have portaudio in its core repository (though you can add Its-pointless's repo to achive it). Even if you get portaudio and pyaudio installed it doesnt support microphone input as of now due to some limitations.

@EightNice
Copy link

Termux has a pkg called termux-api which includes termux-speech-to-text command that can be run from termux to record audio and directly convert it to text.

Install it using:

pkg install termux-api -y

To test, run:

termux-speech-to-text

There will be a beep after which you can speak and it gives output in text.

This can be used along with subprocess module within python to get the output and store it to a string.

import subprocess

inp = subprocess.getoutput("termux-speech-to-text")
print("You said: "+str(inp))

if inp == "Hello":
   print("Termux : Hello I am termux")

It uses Androids inbuit speech recognition feature with o ly downside that if you dont speak after the beep it will terminate with None as output.

Hello! Is there any way to configure that to recognize spanish?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants