You should register the QiSDK in the onCreate Method. Once it register the QiSDK it will trigger the overwritten onRobotFocusGained Method, where you get your qiContext.
What you are doing in the speak() Method is registering the QiSDK that will call the onRobotFocusGained where nothing happens and then you set the Global qiContext that is null to itself. So it will be null.
You should set it in the onRobotFocusGained.
I changed your code to:
public class MainActivity2 extends RobotActivity implements RobotLifecycleCallbacks { private static final String TAG = "MainActivity"; private QiContext qiContext; StringBuilder message; private Object SpeechEngine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE); message = new StringBuilder(); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, new IntentFilter("incomingMessage")); Button BTSettings = (Button) findViewById(R.id.BTSettings); BTSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent BTSettingsIntent = new Intent(MainActivity2.this, BluetoothSettings.class); startActivity(BTSettingsIntent); } }); QiSDK.register(this,this); } BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String text = intent.getStringExtra("theMessage"); message.append(text); Log.d(TAG, "onReceive: Message:" + message); Phrase phrase = new Phrase(message.toString()); speak(phrase); message.delete(0,100); } }; public void speak(Phrase phrase){ FutureUtils.wait(0, TimeUnit.SECONDS).andThenConsume((ignore) -> { Say say = SayBuilder.with(qiContext) .withPhrase(phrase) .build(); say.run(); }); } @Override public void onRobotFocusGained(QiContext qiContext) { this.qiContext = qiContext; } @Override public void onRobotFocusLost() { } @Override public void onRobotFocusRefused(String reason) { } @Override protected void onDestroy(){ QiSDK.unregister(this,this); super.onDestroy(); } }
Thank you so much! It had moved that around quite a bit to see if it worked but i guess i never got the magic combination :D It works now
Cgma20
Hello,
I am trying to get Pepper to say an incoming message that i send over a Bluetooth connection. I can currently send the message, receive the message on my pepper application and do something with that message such as write it to the logs. But i am currently facing the issue of getting pepper to say the message that i send. I have tried several different ways and the closest i have gotten is the current code which returns the error code "missing qiContext or speechengine"