Code Monkey home page Code Monkey logo

Comments (29)

twister21 avatar twister21 commented on August 29, 2024 1

This first information I would like to get is whether the Google API allows such a long connection. Otherwise we can't do anything. But it would be also an idea to use the Google Cloud Speech API.

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024 1

The project is using a private Speech API (https://console.cloud.google.com/apis/library/speech-json.googleapis.com/?filter=visibility:private&project=speech-153718&hl=de)

The official API from Google is https://cloud.google.com/speech/

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024 1

I've created my own API key.

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024 1

First I had to be a member of the Chromium Google group. Then I opened https://console.cloud.google.com/home/ and saw the Google Speech API in a list of APIs being available.
Here I've created my API-Key: https://console.cloud.google.com/apis/credentials?project=speech-153718&hl=de ("speech" ist the name of my project)

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024 1

Sometimes I'm getting this error, too. I think you just have to wait.

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024 1

I just had to realize that the Google Cloud Speech API ist for commercial use only. Furthermore I experienced that the private Google Speech API will abort the connection if there is no uploaded speech for a specific time. I've found: "continuous = Used in full-duplex to keep the stream open and transcoding as long as there is no silence."

The only oppurtinity to keep the stream open would be to send spoofed packets to the server (or something like this).
It would be my dream to realize a voice control for my room with my Raspberry Pi. Unfortunately, it doesn't seem to be realistic at the moment.

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

Also other users have reported this problem . From my experience touching the code of the library that's one problem . I see somewhere a method saying that is good to terminate connection every 15 seconds and then restart it with a Thread (Something with data audio chunks) . Not too difficult to do but it's a problem .

I forked this library and modified it , so i am not the original author . But :
I am using it with XR3Player , so definitely i will improve it as soon as i take it seriously .

1)Let me know after how much time the connection aborts .
2)Can you have a look inside the Library , maybe you can also improve things :) .

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024

Thanks for the reply. I've already tried to get in contact with the original author of the project. Unfortunately, I haven't got any answer yet.

The problem of reconnecting to the Google server every 15 seconds is that the reconnect is counted as query, so that the quota of my API key is wasted.

I hoped that there is any solution since I've already tried a lot of different code changes to fix the problem.

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024

It seems like the connection usually aborts after four or five minutes.

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

Isn't this project already using Google Cloud Speech API? Am I wrong?

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 Seems a lot of work to be done , except of only changing urls ... in order to work with Google Speech API , damn .

I will give it a try .

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024

Yes, but I didn't find a solution for creating a connection being alive for more than five minutes with the Chromium Speech API. It would be very helpful to know if it is Google's fault that the connection is terminated after a certain period of time.

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 Here is the official API from Google Cloud -> Currently in Alpha .

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 Are you using the API key i provided in this repository in order to run your project ?

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 Can you show me how you did it ? I would like to know :) .

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 I enabled Speech API on google cloud platform . Then created an API-Key as you said and tried it inside the Speech Recognition but i am getting this :

Starting to write data to output...
Error: 403
Error has occured

Why that might happens ? Thanks for helping me :) Do i have to create a project like you did ? I am completely new on this .

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 :) I created a similar project like yours -> https://console.cloud.google.com/home/dashboard?project=speech-recognition-187118 , created simple API Key on Credentials .

I think i am missing something here , how did you become a member to Chromium Google group ? Is there a link , i find random links on Google like this

I am always bad at the beggining , until i understand how this works ...

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024

https://www.chromium.org/developers/how-tos/api-keys

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 Ok i found which was the problem , i had not enabled private Speech API so

First i enabled -> Google Speech API for the new Project
Second i enabled -> Private Speech API

image

Tataaa!!! I will upload a tutorial on youtube , now i am reading the code for Official Google Speech API and checking if one is superior to other , or are the same with different parameters ...

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 We share the shame dream , don't worry i will try harder :) . I am looking many topics this period and left behind a little bit this library . I am very glad you are investigating . Hm so if we send spoofed packets ... well that can't be so hard , can it ?

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 Google has a library on Github about Google Cloud Speech API -> It is on Alpha -> https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-speech

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

I can find some code here and there -> https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/speech/cloud-client/src/main/java/com/example/speech/Recognize.java

And https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/speech

And https://cloud.google.com/speech/docs/reference/libraries

If i add it to read from Microphone the data , we are done with this :)

from java-google-speech-api.

twister21 avatar twister21 commented on August 29, 2024

Did you find a solution?

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@twister21 I started working on a StartUp company so i have not too much time currently to investigate . I will , i will , i will :) I am learning Ruby currently and many more .

from java-google-speech-api.

DeathStrokeAlpha avatar DeathStrokeAlpha commented on August 29, 2024

I have a workaround for this.. Use Timer in Swing to call record button's action after every 4 minutes. Hope this helps

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@DeathStrokeAlpha We should implement official Google Cloud Speech API .

from java-google-speech-api.

DeathStrokeAlpha avatar DeathStrokeAlpha commented on August 29, 2024

@goxr3plus of course we should. I was just offering a workaround for that problem.. After 4 minutes the connection will be reset so there will be no disconnection after 5 minutes because the connection will never stay alive for 4 minutes 😊

from java-google-speech-api.

goxr3plus avatar goxr3plus commented on August 29, 2024

@DeathStrokeAlpha @twister21 Hello my friends , i am working with Google Cloud Speech Library so :

Here is working code Google Cloud Speech Official

Any problems you might have about setting the credentials check this stackoverflow question i did :

For some reason it has the same problem as this library , stopping after 65 seconds , google has made it like this .... gonna find a work around soon

Check this -> googleapis/google-cloud-java#3188

package googleSpeech;

import java.io.IOException;
import java.sql.Date;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.HashMap;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.TargetDataLine;

import com.google.api.gax.rpc.ClientStream;
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.StreamController;
import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.speech.v1.RecognitionConfig;
import com.google.cloud.speech.v1.SpeechClient;
import com.google.cloud.speech.v1.StreamingRecognitionConfig;
import com.google.cloud.speech.v1.StreamingRecognizeRequest;
import com.google.cloud.speech.v1.StreamingRecognizeResponse;
import com.google.protobuf.ByteString;

public class GoogleSpeechTest {
	
	public GoogleSpeechTest() {
		
		//Set credentials?
		//	GoogleCredentials credentials = GoogleCredentials.create(new AccessToken("AIzaSyCtrBlhBiqNd7kI4BiOn2kWiCYlwp1azVM",Date.valueOf(LocalDate.now())));
		//	System.out.print(credentials.getAccessToken());
		
		//Target data line
		TargetDataLine microphone;
		AudioInputStream audio = null;
		
		//Check if Microphone is Supported
		checkMicrophoneAvailability();
		
		//Print available mixers
		//printAvailableMixers();
		
		//Capture Microphone Audio Data
		try {
			
			// Signed PCM AudioFormat with 16kHz, 16 bit sample size, mono
			AudioFormat format = new AudioFormat(16000, 16, 1, true, false);
			DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
			
			//Check if Microphone is Supported
			if (!AudioSystem.isLineSupported(info)) {
				System.out.println("Microphone is not available");
				System.exit(0);
			}
			
			//Get the target data line
			microphone = (TargetDataLine) AudioSystem.getLine(info);
			microphone.open(format);
			microphone.start();
			
			//Audio Input Stream
			audio = new AudioInputStream(microphone);
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		//Send audio from Microphone to Google Servers and return Text
		try (SpeechClient client = SpeechClient.create()) {
			
			ResponseObserver<StreamingRecognizeResponse> responseObserver = new ResponseObserver<StreamingRecognizeResponse>() {
				
				public void onStart(StreamController controller) {
					System.out.println("Started....");
				}
				
				public void onResponse(StreamingRecognizeResponse response) {
					System.out.println(response.getResults(0));
				}
				
				public void onComplete() {
					System.out.println("Complete");
				}
				
				public void onError(Throwable t) {
					System.err.println(t);
				}
			};
			
			ClientStream<StreamingRecognizeRequest> clientStream = client.streamingRecognizeCallable().splitCall(responseObserver);
			
			RecognitionConfig recConfig = RecognitionConfig.newBuilder().setEncoding(RecognitionConfig.AudioEncoding.LINEAR16).setLanguageCode("en-US").setSampleRateHertz(16000)
					.build();
			StreamingRecognitionConfig config = StreamingRecognitionConfig.newBuilder().setConfig(recConfig).build();
			
			StreamingRecognizeRequest request = StreamingRecognizeRequest.newBuilder().setStreamingConfig(config).build(); // The first request in a streaming call has to be a config
			
			clientStream.send(request);
			
			//Infinity loop from microphone
			while (true) {
				byte[] data = new byte[10];
				try {
					audio.read(data);
				} catch (IOException e) {
					System.out.println(e);
				}
				request = StreamingRecognizeRequest.newBuilder().setAudioContent(ByteString.copyFrom(data)).build();
				clientStream.send(request);
			}
		} catch (Exception e) {
			System.out.println(e);
		}
		
	}
	
	/**
	 * Checks if the Microphone is available
	 */
	public static void checkMicrophoneAvailability() {
		enumerateMicrophones().forEach((string , info) -> {
			System.out.println("Name :" + string);
		});
	}
	
	/**
	 * Generates a hashmap to simplify the microphone selection process. The keyset is the name of the audio device's Mixer The value is the first
	 * lineInfo from that Mixer.
	 * 
	 * @author Aaron Gokaslan (Skylion)
	 * @return The generated hashmap
	 */
	public static HashMap<String,Line.Info> enumerateMicrophones() {
		HashMap<String,Line.Info> out = new HashMap<String,Line.Info>();
		Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
		for (Mixer.Info info : mixerInfos) {
			Mixer m = AudioSystem.getMixer(info);
			Line.Info[] lineInfos = m.getTargetLineInfo();
			if (lineInfos.length >= 1 && lineInfos[0].getLineClass().equals(TargetDataLine.class))//Only adds to hashmap if it is audio input device
				out.put(info.getName(), lineInfos[0]);//Please enjoy my pun
		}
		return out;
	}
	
	/**
	 * Print available mixers
	 */
	public void printAvailableMixers() {
		
		//Get available Mixers
		Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
		
		//Print available Mixers
		Arrays.asList(mixerInfos).forEach(info -> {
			System.err.println("\n-----------Mixer--------------");
			
			Mixer mixer = AudioSystem.getMixer(info);
			
			System.err.println("\nSource Lines");
			
			//SourceLines
			Arrays.asList(mixer.getSourceLineInfo()).forEach(lineInfo -> {
				//Line Name
				System.out.println(info.getName() + "---" + lineInfo);
				Line line = null;
				try {
					line = mixer.getLine(lineInfo);
				} catch (LineUnavailableException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("\t-----" + line);
			});
			
			System.err.println("\nTarget Lines");
			//TargetLines
			Arrays.asList(mixer.getTargetLineInfo()).forEach(lineInfo -> {
				
				//Line Name
				System.out.println(mixer + "---" + lineInfo);
				Line line = null;
				try {
					line = mixer.getLine(lineInfo);
				} catch (LineUnavailableException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println("\t-----" + line);
				
			});
			
		});
	}
	
	public static void main(String[] args) {
		new GoogleSpeechTest();
	}
	
}

from java-google-speech-api.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.