forked from KilianB/Java-Sonos-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoiceToTextLauncher.java
More file actions
90 lines (66 loc) · 2.14 KB
/
VoiceToTextLauncher.java
File metadata and controls
90 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.github.kilianB.example.voiceToTextPlayback;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Logger;
import com.github.kilianB.NetworkUtil;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
/**
* @author Kilian
*
*/
public class VoiceToTextLauncher extends Application {
private final static Logger LOGGER = Logger.getLogger(VoiceToTextLauncher.class.getName());
/*
* We create our own mp3 file. In order for sonos to play it back
*/
private InetAddress hostAddress;
private NetworkFileProvider fileProvider;
//Ephemeral ports 49152 to 65535
private int port = 63258;
public VoiceToTextLauncher() {
//Local file hosting.
try {
hostAddress = NetworkUtil.resolveSiteLocalAddress();
} catch (IOException e) {
try {
hostAddress = InetAddress.getLocalHost();
}catch(UnknownHostException e1) {
e1.printStackTrace();
}
LOGGER.severe("Could not resolve a valid ip adress. fallback to localhost " + e);
}
fileProvider = new NetworkFileProvider(hostAddress.getHostAddress(),port,new String[] {"mp3"});
File hostedFolder = new File("mp3TempFiles");
hostedFolder.mkdirs();
fileProvider.mapFolder(hostedFolder);
}
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
loader.setController(new VoiceToTextController(fileProvider));
loader.setLocation(getClass().getResource("VoiceToText.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("SonosIcon.png")));
primaryStage.setTitle("Sonos Text To Speech");
primaryStage.show();
}
@Override
public void stop() {
fileProvider.deinit();
}
/**
* @param args
*/
public static void main(String[] args) {
launch(args);
}
}