Android/python : is ttsSpeak non blocking? - android

I have written a small app on Android using python (Qpython3) with voice synthesizer & voice recognition.
droid = sl4a.Android()
droid.ttsSpeak("hello")
v = str(droid.recognizeSpeech()
droid.ttsSpeak(v)
The synthesized voice is then saying a first "hello", and then once again it says "hello" as if it was auto-recording the first string - and I interpret this as ttsSpeak non blocking.
Is there a way to wait for the completion of the voice synthesizer before starting the voice recognizer ?

found in In Love with a Droid
need to wait via ttsIsSpeaking which returns a tuple, the boolean is the second element of the tuple is set false when the current speak has completed.

Related

ML Kit ASR error: Error code:40,subError code:3005,errorMessage: Service unavailable

I've been developing a demo for speech recognition and ran into an issue. Could anyone help me? I called startRecognizing interface and received an onError callback (Error 11203, subError 3005, errorMessage: service unavailable), see screenshot:
I followed the document , My code:
// Create an Intent to set parameters.
val mSpeechRecognizerIntent = Intent(MLAsrConstants.ACTION_HMS_ASR_SPEECH)
// Use Intent for recognition parameter settings.
mSpeechRecognizerIntent
// Set the language that can be recognized to English. If this parameter is not set, English is recognized by default. Example: "zh-CN": Chinese; "en-US": English; "fr-FR": French; "es-ES": Spanish; "de-DE": German; "it-IT": Italian; "ar": Arabic; "th_TH": Thai; "ms_MY": Malay; "fil_PH": Filipino.
.putExtra(MLAsrConstants.LANGUAGE, "en-US") // Set to return the recognition result along with the speech. If you ignore the setting, this mode is used by default. Options are as follows:
// MLAsrConstants.FEATURE_WORDFLUX: Recognizes and returns texts through onRecognizingResults.
// MLAsrConstants.FEATURE_ALLINONE: After the recognition is complete, texts are returned through onResults.
.putExtra(MLAsrConstants.FEATURE, MLAsrConstants.FEATURE_WORDFLUX) // Set the application scenario. MLAsrConstants.SCENES_SHOPPING indicates shopping, which is supported only for Chinese. Under this scenario, recognition for the name of Huawei products has been optimized.
.putExtra(MLAsrConstants.SCENES, MLAsrConstants.SCENES_SHOPPING)
// Start speech recognition.
mSpeechRecognizer.startRecognizing(mSpeechRecognizerIntent)
Do you have any idea why this could be happening? Please help, thanks!!
You need to change "en-US" to "zh-CN".
Or comment out ".putExtra(SCENES, SCENES_SHOPPING)":

Android - Speech Recognition - No recognition result matched

I am trying to implement speech recognition. I keep getting the error:
ERROR_NO_MATCH - No recognition result matched - 7
I can't find anything that explain what does this means.
What does "No recognition result matched" mean?
you need to enable partial results first, and to call UNSTABLE_TEXT
// When creating the intent, set the partial flag to true
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS,true);
use the partialResults returned in onPartialResults(). In the returned bundle "SpeechRecognizer.RESULTS_RECOGNITION" has all the terms minus the last term and "android.speech.extra.UNSTABLE_TEXT" has the last missing recognized term.
#Override
public void onPartialResults(Bundle partialResults) {
ArrayList<String> data =
partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
ArrayList<String> unstableData =
partialResults.getStringArrayList("android.speech.extra.UNSTABLE_TEXT");
mResult = data.get(0) + unstableData.get(0);
}
you can follow below link for better understanding -
speech recognition
No recognition result matched. Meaning superbox s3 cannot us voice command message no recognition result matched . Come up on screen

Setting sound configuration for Socket device

Using the following code to attempt setting the sound on/off for a Socket 8ci...not quite working for me. Can you suggest a proper command? As you can see in the code I set the Sound frequency based on a preference boolean. Thanks!
DeviceInfo device = (DeviceInfo) _scanApiHelper.getDevicesList().lastElement();
short[] soundConfig = new short[3];
// default the sound to On
if(getBRSharedPreferenceBoolean(PreferencesActivity.PREF_SOCKET_SCANNER_BEEP, true)) {
soundConfig[0] = ISktScanProperty.values.soundFrequency.kSktScanSoundFrequencyHigh;
} else {
soundConfig[0] = ISktScanProperty.values.soundFrequency.kSktScanSoundFrequencyNone;
}
soundConfig[1] = 200;
soundConfig[2] = 100;
// set the scanner sound config
_scanApiHelper.postSetSoundConfigDevice(
device,
ISktScanProperty.values.soundActionType.kSktScanSoundActionTypeGoodScan,
soundConfig,
_onSetScanApiConfiguration);
The Problem
Sound Config Device
The sound config allows you to set 4 different "actions": kSktScanSoundActionTypeGoodScan, kSktScanSoundActionTypeGoodScanLocal, kSktScanSoundActionTypeBadScan, kSktScanSoundActionTypeBadScanLocal. The difference between GoodScan and BadScan is self-explanatory, but the difference between GoodScan and GoodScanLocal isn't very clear.
GoodScanLocal, by default, is the sound emitted when a barcode is scanned
GoodScan is only emitted when the host (e.g. Android, iOS, Windows) sends the scanner a GoodScan or BadScan notification (via kSktScanPropIdDataConfirmationDevice)
Note: If you are using GoodScan/BadScan to verify decoded data, you probably want to change the confirmation mode (see kSktScanPropIdDataConfirmationMode in the docs). Otherwise the scanner will beep/flash/vibrate twice per scan
The code snippet your snippet is based on uses the latter to demonstrate that the tone is both configurable and can be triggered by the host.
You select a tone, hit the confirm button and the scanner emits that tone. It's not clear at first glance, but if you change the tone using the dropdown in SingleEntry and hit confirm, the three tones are very distinct. However, if you change the tone using that same dropdown, the tone you hear when you scan a barcode should not change.
The Solution
The best and simplest way to achieve what you are trying to achieve is to set the Local Decode Action with the beep disabled
Local Decode Action
// import static com.socketmobile.scanapi.ISktScanProperty.values.localDecodeAction.*;
DeviceInfo device = (DeviceInfo) _scanApiHelper.getDevicesList().lastElement();
int decodeAction = kSktScanLocalDecodeActionFlash | kSktScanLocalDecodeActionRumble;
if(getBRSharedPreferenceBoolean(PreferencesActivity.PREF_SOCKET_SCANNER_BEEP, true)) {
decodeAction |= kSktScanLocalDecodeActionBeep;
}
_scanApiHelper.postSetDecodeAction(device, decodeAction)
For completeness sake, to achieve a similar result using the code you posted, you'd only need to change kSktScanSoundActionTypeGoodScan to kSktScanSoundActionTypeGoodScanLocal. Although I would not recommend it.

How can I send data to an already running thread with a loop in python?

So here I got a question! How can I send and receive data from a simple thread who's job is to keep playing songs!? I want a way to send data to the thread to stop iterating a list of songs. It can be a file descriptor, variable(global), properties/options, database entry, or even an event.
Here is the code:
def ControlPlay(ControlAction):
SongList = DarkCore.mediaPlayList().result
while ControlAction:
for Song in SongList:
if DarkCore.mediaIsPlaying(Song).result == False:
print "Now Playing:" , Song
DarkCore.mediaPlayStart(Song)
while DarkCore.mediaIsPlaying(Song).result:
continue
import android # Python For Android
DarkCore = android.Android()
import threading
t = threading.Thread(target=ControlPlay, args=(True,))
t.start()
I may get a Stop from multiple sources(devices) using different protocols like wifi via socket(ssh tunnel), bluetooth or serial that extend over a range of protocols and actions. All I want is a way to identify and declare an action based on what another thread or main loop sends.
A simple explanation.. Thanks for your understanding! Any help is appreciated.

Sending pause to dialer

In a similar vein to Sending Pause and DTMF input in android, I'm trying to send the pause character "," to the dialer. This works on HTC Sense phones and even on the Xoom, but not on "stock experience" phones like the Nexus One or T-Mobile G2 (and I suspect the Motorola Droid).
These phones seem to have a dialer that tries to pretty-format the number (ie adding dashes) and stop upon hitting a comma character. Interestingly, it doesn't choke on a "p" character, though it will strip out "p"s and keep adding numbers.
Here is what the ActivityManager sees:
I/ActivityManager( 92): Starting activity: Intent { act=android.intent.action.DIAL dat=tel:8883333,444 cmp=com.android.contacts/.DialtactsActivity }
I've also tried the encoded form, "tel:8883333%2C444" with no difference in behavior on these phones. I've tried "p", as mentioned, but these characters are dropped resulting in the dialers having 888-333-3444 incorrectly populated, and I'm not sure that "p" is correct anyway.
So, the question: Is there a way to specify a pause that works across most or all android dialers?
Short answer: Doesn't look like it's possible using the native dialer.
Long answer:
The native dialer in Android uses the following code to extract the number you pass in to the dialer using an Intent
if ("tel".equals(uri.getScheme())) {
// Put the requested number into the input area
String data = uri.getSchemeSpecificPart();
setFormattedDigits(data, null);
return true;
}
Within the setFormattedDigits method the number gets transformed thusly:
String dialString = PhoneNumberUtils.extractNetworkPortion(data);
Looking at the docs for extractNetworkPortion you'll notice that it, "Extracts the network address portion [where the] Network address portion is everything up to DTMF control digit separators (pause or wait).
So the code is intentionally striping out the pause character and anything that comes after it. The only alternative I can think of is to replace the dialer or use the ACTION_CALL action instead of ACTION_DIAL. That'll bypass the dialer, so it should be used with caution.
dialing pause has been comma for 30 years
If the android phone is compatible with ITUT V.250 ATS8=2 should set the delay caused by comma to 2 seconds. (it's possible that it has somehow been set to 0s)
ITUT is a great standards orgnisation, you can download their standards for free.
From the android's latin ime source code:
<!-- Pause is a comma. Check PhoneNumberUtils.java to see if this has changed. -->
<Key
android:codes="44"
android:keyLabel="Pause" />
I am not 100% sure if it's public, but you might be able to use:
PhoneNumberUtils.PAUSE
',' is the standard but HTC used 'p' in rogers magic,, have you tried with 'p'?
HTC Magic is using p
This is horrible and dangerous. Business people getting conference call emails on their phone have to constantly switch back and forth to get the number.
Just make it work like it should:
tel://+1-877-555-1212,,,2345678#
Should dial the 877 number pause then dial in the participant conference code and 'enter' (#) when selected anywhere on the phone.
It's that simple. The fact this doesn't work in Android is a iPhone sales pitch.
For future reference RFC-2806 specifies storing telephone numbers in the format:
tel:number;postd=post-dial
Where number can start with + for intentional dialling and can include - or . as a visual separator and post-dial can include numbers, upper case letters A-D, #, *, p for pause and w for wait.

Categories

Resources