I recently installed Voce and am using it in my Java application. In Eclipse, I added the JAR files in voce-0.9.1/voce-0.9.1/lib to the libraries in my Java Build Path. From the documentation, I figured that this code should work:
import voce.SpeechSynthesizer;
public class Test
{
public static void main(String[] args)
{
// System.out.println("Speaking");
SpeechSynthesizer speaker = new SpeechSynthesizer("speaker");
speaker.synthesize("hello");
// System.out.println("Spoken");
speaker.destroy();
}
}
When I uncomment the output statements, the program outputs "Speaking", then almost immediately outputs "Spoken" without having made a sound. My volume is turned up. Does synthesize() speak the string or have I forgotten some initialization? And can you give me some code that should work?
Answer
Here is the code that worked (I used the static methods in SpeechInterface instead of a SpeechSynthesizer object):
public class Test
{
public static void main(String[] args)
{
voce.SpeechInterface.init("../../../lib", true, false, "", "");
System.out.println("Speaking");
voce.SpeechInterface.synthesize("hello");
System.out.println("Spoken");
try { Thread.sleep(1000); } catch(Exception ex) {}
voce.SpeechInterface.destroy();
}
}
Related
I want my GameServer to run separately from the game itself. So, players(clients) can join into one static GameServer and I can handle them together and see how many clients are connected, currently.
But the problem is, I can only run only one of these classes(GameServer.main() and DesktopLauncher.main()) at the same time. GameServer must be running always at the background if I'm not wrong, right ? Yet, I can't run the game itself without stopping the GameServer. (It stucks saying Executing task 'DesktopLauncher.main()'...) I have some pictures to realize what's going on and what project structure looks like :
Pic 1 , Pic 2 , Pic 3
Here is my project structure :
core
-java
--com.mygdx.game
---Multiplayer
----Packets
-----GameClient.java
-----GameServer.java
-----GameClientListener.java
-----GameServerListener.java
---screens
---utils
---Application.java
GameServer.class
package com.mygdx.game.Multiplayer;
imports..
public class GameServer {
public int TCP_PORT,UDP_PORT;
public Server server;
public GameServerListener listener;
public static int totalClients = 0;
public GameServer() {
TCP_PORT = UDP_PORT = xxxx;
server = new Server(TCP_PORT,UDP_PORT);
listener = new GameServerListener(this);
startServer();
}
public void startServer() {
server.addListener(listener);
try {
server.bind(TCP_PORT,UDP_PORT);
//server.bind(TCP_PORT);
} catch (IOException e) {
e.printStackTrace();
}
registerPackets();
server.start();
}
private void registerPackets() {
server.getKryo().register(LoginRequest.class);
server.getKryo().register(LoginResponse.class);
server.getKryo().register(ChoiceRequest.class);
server.getKryo().register(ChoiceRespond.class);
}
public static void main(String[] args) {
new GameServer();
}
}
Thanks for any help.
Had the same issue. Downgrading to Android Studio 3.4 worked for me.
Check: https://www.reddit.com/r/libgdx/comments/fxrlsm/unable_to_run_two_or_more_application_in_parallel/
I am trying to use AspectJ in sample project in IntelliJ IDEA. I have an experience with Spring AOP, but this is first time I am using AspectJ, and cannot make it work.
Environment:Win 10, IntelliJ IDEA and AspectJ,
Refer to this document for configuration,
https://www.jetbrains.com/help/idea/2016.3/aspectj.html
public class Hello {
public void sayHello() {
System.out.println("test1.Hello, AspectJ!");
}
public static void main(String[] args) {
Hello hello = new Hello();
hello.sayHello();
}
}
public aspect TxAspect {
void around():call(void Hello.sayHello()){
System.out.println("Start transaction...");
proceed();
System.out.println("end transaction...");
}
}
It should hava outputs:
Start transaction...
Hello, AspectJ!
end transaction...
but it appears a lot of errors:
enter image description here
Change the jdk release from 10 to 8 can solve this problem.
I'm currently working on my discord bot. One problem I encountered is that I'm not able to find out how to allow the bot to wait for a user reply after a message is sent.
I also have tried reading the git documentation regarding using RestAction over here: https://github.com/DV8FromTheWorld/JDA/wiki/7)-Using-RestAction but it seems it does not mention anything about implementing an "await" function similar to discord.js
I tried coding to mimic such an effect:
public class EventHandler extends ListenerAdapter {
private static final String PREFIX = "&";
public static String[] args;
public void sendMessage(String s, GuildMessageReceivedEvent event) {
event
.getChannel()
.sendMessage(s)
.queue();
}
public void onGuildMessageReceived (GuildMessageReceivedEvent event) {
args = event
.getMessage()
.getContentRaw()
.split(" ");
if (args[0].equalsIgnoreCase(PREFIX + "any_command")) {
sendMessage("Type hello!");
if (args[0].equalsIgnoreCase(PREFIX + "hello") {
sendMessage("hello there!");
}
}
}
}
Main class:
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
public class Main {
public static void main(String[] args) throws Exception {
JDA jda = new JDABuilder(AccountType.BOT)
.setToken("token goes here")
.setAutoReconnect(true).build();
try {
jda.addEventListener(new EventHandler());
} catch (Exception e) {
e.printStackTrace();
}
}
}
This doesn't register the hello command typed after the prompt given. My best guess would be that the condition is never met since the original condition overrides the upcoming one (args[0] is already any_command)
Any help would be appreciated!
I'd suggest the EventWaiter from JDA-Utilities (https://github.com/JDA-Applications/JDA-Utilities/)
Taking a quick look at the source, looks like you'll need something like this
EventWaiter waiter = new EventWaiter();
// SO wouldn't let me insert new lines for some reason.
waiter.waitForEvent(GuildMessageReceivedEvent.class, (event) -> event.getMessage().getContentRaw().equalsIgnoreCase("hello"), (event) -> event.getChannel().sendMessage("hello!").queue()));
I've never used java windowbuilder before, however I'm trying to test it with my program which performs operations on sets. It's a Gradle project. I wrote all classes in the default package (I knew that it's discouraged just when I was finished). The program reads a line of operations on sets, parses it and prints the result and keeps doing that while there is a new line input from the user.
I'm trying to make a simple GUI for this program using windowbuilder but I can't figure out how to run the main class in the windowbuilder class and make it take input from a jtextfield and prints output.
My main looks like this:
public static void main(String[] argv) {
new Main().start();
}
private void start() {
hmap = new HashMap<IdentifierInterface, SetInterface<BigInteger>>();
Scanner in = new Scanner(System.in);
// While there is input, read line and parse it.
while (in.hasNextLine()) {
try {
String statement = in.nextLine();
if (statement.trim().isEmpty()) {
System.out.println("error, no statement");
} else {
Scanner statementScanner = new Scanner(statement);
readStatement(statementScanner);
}
} catch (APException e) {
System.out.printf("%s\n", e.getMessage());
}
}
}
I made a new windowbuilder class, with the buttons and text fields, but I got stuck on how to run my main inside the windowbuilder. Your help is appreciated. Thanks in advance.
Eclipse RCP applications are OSGi plug-ins; they do not have a main() method.
Instead your Main class should look like this:
package com.myplugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Main implements BundleActivator {
#Override
public void start(BundleContext bundleContext) throws Exception {
// Copy your start logic here
}
}
Then edit META-INF/MANIFEST.MF file and set for example
Bundle-Activator: com.myplugin.Main
This makes your Main class the activator of the plug-in: start() will be invoked at load.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Exception in thread “main” java.lang.NoSuchMethodError: main
I am fairly new to Java, and I am unable to figure out why I am getting NoSuchMethodError: main when I execute the following code. I am not sure what does the NoSuchMethodError is pertaining to. It looks like I have everything right. Please help me out here. Thanks a lot.
public class ThreadExample1 extends Thread
{
static String[] msg = {"Java", "programming", "is", "the", "best"};
public ThreadExample1(String id)
{
super(id);
}
#Override
public void run()
{
try
{
Output.displayList(getName(), msg);
}
catch (InterruptedException ex)
{
}
}
}
class Output
{
public static void displayList(String name, String list[]) throws InterruptedException
{
for (int i = 0; i < list.length; i++)
{
Thread.currentThread().sleep((long) (3000 * Math.random()));
System.out.println(name + list[i]);
}
}
public static void main(String[] args)
{
ThreadExample1 thread1 = new ThreadExample1("thread1: ");
ThreadExample1 thread2 = new ThreadExample1("thread2: ");
thread1.start();
thread2.start();
boolean t1IsAlive = true;
boolean t2IsAlive = true;
do
{
if (t1IsAlive && !thread1.isAlive())
{
t1IsAlive = false;
System.out.println("t1 is dead.");
}
if (t2IsAlive && !thread2.isAlive())
{
t2IsAlive = false;
System.out.println("t2 is dead.");
}
}while (t1IsAlive || t2IsAlive);
}
}
I don't have any problem compiling and executing the above code ... Keep in mind that when you want to execute it , you need to use this command line :
java Output
and NOT :
java ThreadExample1
because the main method is within the Output calss and not in ThreadExample1 ...
Save the file as ThreadExample1.java and compile. After that you should run Output class but not the ThreadExample1 class. This is because you have added your main method inside Output class. But since you have made your ThreadExample1.java class public you have to save and compile using that name(javac ThreadExample1.java). After that java Output
Take a look at code-snippet the main() method is in Output class.
Use following command line to launch the Output.main() method:
c:\>java Output
When you do compile a java program you do need to give the file name after javac.
like javac MyProgram.java
and when you do run it using java then you need to mention the name of the class that is having "public static void main(String args[])" method.
Say I have two classes in MyProgram.java : Class First and Class Second
and I have "public static void main(String args[])" in Class Second then I will do the following :
javac MyProgram.java
java Second