-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb18d0b
commit 803cf60
Showing
10 changed files
with
246 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
marvin.robot.core/src/main/java/com/assetvisor/marvin/robot/domain/brain/Brain.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.assetvisor.marvin.robot.domain.brain; | ||
|
||
import com.assetvisor.marvin.robot.domain.communication.ConversationMessage; | ||
import com.assetvisor.marvin.robot.domain.communication.ForCheckingIfAnybodyIsListening; | ||
import com.assetvisor.marvin.robot.domain.communication.ForConvertingSpeechToText; | ||
import com.assetvisor.marvin.robot.domain.communication.ForConvertingTextToSpeech; | ||
import com.assetvisor.marvin.robot.domain.communication.ForTexting; | ||
import com.assetvisor.marvin.robot.domain.communication.SpeechMessage; | ||
import com.assetvisor.marvin.robot.domain.communication.SpeechBuffer; | ||
import com.assetvisor.marvin.robot.domain.communication.TextMessage; | ||
import com.assetvisor.marvin.robot.domain.environment.Observation; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
public class Brain { | ||
|
||
private static final Log LOG = LogFactory.getLog(Brain.class); | ||
|
||
private final ForTexting forTexting; | ||
private final ForConvertingTextToSpeech forConvertingTextToSpeech; | ||
private final ForConvertingSpeechToText forConvertingSpeechToText; | ||
private final ForCheckingIfAnybodyIsListening forCheckingIfAnybodyIsListening; | ||
private final SpeechBuffer speechBuffer; | ||
private final ForInvokingIntelligence forInvokingIntelligence; | ||
|
||
public Brain(ForTexting forTexting, | ||
ForConvertingTextToSpeech forConvertingTextToSpeech, | ||
ForConvertingSpeechToText forConvertingSpeechToText, | ||
ForCheckingIfAnybodyIsListening forCheckingIfAnybodyIsListening, | ||
SpeechBuffer speechBuffer, | ||
ForInvokingIntelligence forInvokingIntelligence | ||
) { | ||
this.forTexting = forTexting; | ||
this.forConvertingTextToSpeech = forConvertingTextToSpeech; | ||
this.forConvertingSpeechToText = forConvertingSpeechToText; | ||
this.forCheckingIfAnybodyIsListening = forCheckingIfAnybodyIsListening; | ||
this.speechBuffer = speechBuffer; | ||
this.forInvokingIntelligence = forInvokingIntelligence; | ||
} | ||
|
||
public void observe(Observation observation) { | ||
LOG.info(observation); | ||
forInvokingIntelligence.invoke( | ||
observation.toString(), | ||
true, | ||
this, | ||
ConversationMessage.DEFAULT_CONVERSATION_ID | ||
); | ||
} | ||
|
||
public void read(TextMessage message, boolean echoToSender) { | ||
LOG.info(message); | ||
if(echoToSender) { | ||
forTexting.text(message, true); | ||
} | ||
forInvokingIntelligence.invoke( | ||
message.getContent(), | ||
true, | ||
this, | ||
message.conversationId() | ||
); | ||
} | ||
|
||
public void listenTo(SpeechMessage speech) { | ||
String text = forConvertingSpeechToText.convert(speech.getAudio()); | ||
LOG.info(text); | ||
forTexting.text( | ||
new TextMessage( | ||
speech.getSender(), | ||
speech.conversationId(), | ||
text), | ||
true | ||
); | ||
forInvokingIntelligence.invoke( | ||
text, | ||
true, | ||
this, | ||
speech.conversationId() | ||
); | ||
} | ||
|
||
public void respond(String message, String conversationId) { | ||
message(message, conversationId); | ||
if(forCheckingIfAnybodyIsListening.isAnybodyListening()) { | ||
speak(message, conversationId); | ||
} | ||
} | ||
|
||
private void speak(String message, String conversationId) { | ||
byte[] speech = forConvertingTextToSpeech.convert(message); | ||
speechBuffer.add(new SpeechMessage("Marvin", conversationId, speech)); | ||
} | ||
|
||
private void message(String message, String conversationId) { | ||
forTexting.text(new TextMessage("Marvin", conversationId, message), false); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
marvin.robot.core/src/main/java/com/assetvisor/marvin/robot/domain/brain/BrainResponder.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.