コード例 #1
0
ファイル: Socket.java プロジェクト: hulstores/geogebra
  /**
   * Create a session to use realsense camera
   *
   * @throws Exception if no camera installed
   */
  public static void createSession() throws Input3DException {

    if (SESSION != null) {
      return;
    }

    // reset sense manager
    SENSE_MANAGER = null;

    try {
      // Create session
      SESSION = PXCMSession.CreateInstance();
    } catch (Throwable e) {
      throw new Input3DException(
          Input3DExceptionType.INSTALL,
          "RealSense: Failed to start session instance creation, maybe unsupported platform?");
    }
    if (SESSION == null) {
      throw new Input3DException(
          Input3DExceptionType.INSTALL, "RealSense: Failed to create a session instance");
    }
  }
コード例 #2
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // Creating a session.
    PXCMSession session = PXCMSession.CreateInstance();

    // Querying the SDK version
    PXCMSession.ImplVersion sdkVersion = session.QueryVersion();
    System.out.println(
        String.format("RealSense SDK Version %d.%d", sdkVersion.major, sdkVersion.minor));

    // General information about Speech Recognition.
    // Creating an AudioSource
    PXCMAudioSource audioSource = session.CreateAudioSource();

    // Listing the audio devices
    audioSource.ScanDevices();
    int devicesCount = audioSource.QueryDeviceNum();

    if (devicesCount <= 0) {
      System.out.println("There is no audio device available.");
      return;
    }

    System.out.println("Listing audio devices:");

    for (int i = 0; i < devicesCount; i++) {
      PXCMAudioSource.DeviceInfo deviceInfo = new PXCMAudioSource.DeviceInfo();
      audioSource.QueryDeviceInfo(i, deviceInfo);
      System.out.println(String.format("\t%s: %s", deviceInfo.did, deviceInfo.name));
    }

    // Selecting the first device
    PXCMAudioSource.DeviceInfo deviceInfo = new PXCMAudioSource.DeviceInfo();
    audioSource.QueryDeviceInfo(0, deviceInfo);
    audioSource.SetDevice(deviceInfo);

    // Adjusting the audio recording volume.
    audioSource.SetVolume(0.2f);

    // Creating the SpeechRecognition instance
    PXCMSpeechRecognition speechRecognition = new PXCMSpeechRecognition();
    pxcmStatus speechRecognitionStatus = session.CreateImpl(speechRecognition);

    if (speechRecognitionStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
      System.out.println("Failed to create the SpeechRecognition instance");
      return;
    }

    // Configuring the speech module
    List<PXCMSpeechRecognition.ProfileInfo> availableProfiles =
        new ArrayList<PXCMSpeechRecognition.ProfileInfo>();
    System.out.println("Listing the available profiles:");
    for (int i = 0; ; i++) {
      PXCMSpeechRecognition.ProfileInfo profileInfo = new PXCMSpeechRecognition.ProfileInfo();
      pxcmStatus profileQueryStatus = speechRecognition.QueryProfile(i, profileInfo);

      if (profileQueryStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
        break;
      }
      System.out.println(String.format("\t%s", profileInfo.language));
      availableProfiles.add(profileInfo);
    }

    // Setting the first profile
    speechRecognition.SetProfile(availableProfiles.get(0));

    if (DemoRecognitionType
        == RecognitionType
            .DICTATION) // To change the recognition mode, please change the value of the
                        // DemoRecognitionType constant at the beginning of this file.
    {
      //  Seting the dictation mode
      pxcmStatus setDictationStatus = speechRecognition.SetDictation();

      if (setDictationStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
        System.out.println("Failed to create the SpeechRecognition instance");
        return;
      }
    } else {
      // Building a list of commands
      String[] commandsGrammar1 = {"One", "Two", "Three"}; // English
      speechRecognition.BuildGrammarFromStringList(
          1, commandsGrammar1, null, commandsGrammar1.length);

      String[] commandsGrammar2 = {"Um", "Dois", "Três"};
      speechRecognition.BuildGrammarFromStringList(
          2, commandsGrammar2, null, commandsGrammar2.length);

      // Selecting the grammar
      speechRecognition.SetGrammar(1);
    }

    // Handling recognition events
    PXCMSpeechRecognition.Handler handler =
        new PXCMSpeechRecognition.Handler() {
          @Override
          public void OnAlert(PXCMSpeechRecognition.AlertData alertData) {
            System.out.println(alertData.label);
          }

          @Override
          public void OnRecognition(PXCMSpeechRecognition.RecognitionData recognitionData) {
            switch (DemoRecognitionType) { // To change the recognition mode, please change the
                                           // value of the DemoRecognitionType constant at the
                                           // beginning of this file.
              case DICTATION:
                processDictation(recognitionData);
                break;
              case COMMAND:
              default:
                processCommands(recognitionData);
                break;
            }
          }

          public void OnRecognized(PXCMSpeechRecognition.RecognitionData recognitionData) {
            OnRecognition(recognitionData);
          }
        };

    speechRecognition.StartRec(audioSource, handler);

    // Waiting a key to stop voice recognition
    // Console.ReadKey();
    speechRecognition.StopRec();
  }