I try to get a speechrecognizer running in Kotlin with Android Studio.
Having resolved my compiler problems with help from stackoverflow I now face the following problem: The speechRecognizer does no longer end.
I am sure, yesterday after waiting a default time of may be 3 to 5 seconds the speechcontrol ended. When I spoke nothing, the anwer was "try it again" , elsewhere it ended correctly.
Now the "input-Speech-window does not end until i click into the window.
AND I HAVE NO IDEA; WHAT I COULD HAVE CHANGED !!!!
I add the "RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 100" (what is NOT SUGGESTED !!), but also doesn't help
This is the code for the speechrecognizer
fun btnhear(view: View) {
val speechRecognitionIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
speechRecognitionIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault().toString())
speechRecognitionIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 100)
startActivityForResult(speechRecognitionIntent, SPEECHINTENTRQ)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
textView.text = "vor der if loop " + requestCode + " " + resultCode
//var speechresult: String? = String()
if (requestCode == SPEECHINTENTRQ && resultCode == Activity.RESULT_OK) {
textView.text = "in der if loop " + Activity.RESULT_OK
var speechresult2: ArrayList<String> =
data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS) ?: ArrayList()
if (speechresult2.isNullOrEmpty()) {
textView.text = "nothing heard " + Activity.RESULT_OK
}
else {
var spokenText = speechresult2[0]
editText.setText(spokenText)
}
}
else
editText.setText("Keine Eingabe"+requestCode)
//super.onActivityResult(requestCode, resultCode, data)
}
I appreciate any idea, what i could have made wrong.
I run it on emulator und tried 2, Pixel 2 API28 and Pixel API 28
Sorry: my answer is:
I don't know why, but by accident I lost my speech recognition on the Emulator.
I try running / debugging on the smartphone via USB device connection.
Trying for hours to get the speech recognition running again on the emulator, but doesn't work again. Checking lots of internet-tips, trying (i think ALL ) settings, installing google assistant, running with or without login to my account, nothing helped.
It' s a pity, but i think i have to skip it and test directly on the smartphone (I have 3 smartphones with working "Ok google ", but on emulator i fail ....
and testing on smartphone - the app works as expected
Related
My app uses some short sounds for user feedback. I use the following code:
private void playSound(String fileName) {
try {
FileSystemStorage fss = FileSystemStorage.getInstance();
String sep = fss.getFileSystemSeparator() + "";
String soundDir; // sounds must be in a directory
if (fss.getAppHomePath().endsWith(sep)) {
soundDir = fss.getAppHomePath() + "sounds"; // device
} else {
soundDir = fss.getAppHomePath() + sep + "sounds"; // simulator/windows
}
if (!fss.exists(soundDir)) {
// first time a sound is played: create directory
fss.mkdir(soundDir);
}
String filePath = soundDir + sep + fileName;
if (!fss.exists(filePath)) {
// first time this sound is played: copy from resources (place file in <project>/src)
InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/" + fileName);
OutputStream os = fss.openOutputStream(filePath);
com.codename1.io.Util.copy(is, os);
}
Media media = MediaManager.createMedia(filePath, false);
//media.setVolume(100);
media.play();
} catch (IOException ex) {
log("Error playing " + fileName + " " + ex.getMessage());
}
}
Example call:
playSound("error.mp3");
This works fine on devices and in the simulator. However, if I do a long automatic test in the simulator (using Windows), playing a sound about every second,
this eats up all the RAM until Windows crashes. The Windows task manager, however, shows no exceptional memory usage of NetBeans and the Java process.
So my questions are: Is my code correct? Can this happen on devices too? Or else is there a way to prevent this in the simulator/Windows?
P.S.
I also tried the code from How to bundle sounds with Codename One?. That has the same problem and also
some sounds get lost (are not played).
I also tried the simple code from Codename One - Play a sound but that doesn't work.
We generally recommend keeping the Media instance for this sort of use case.
But if you can't just make sure to call cleanup when you're done:
MediaManager.addCompletionHandler(media, () -> media.cleanup());
media.play();
I am working on a small tool to schedule p4 sync daily at specific times.
In this tool, I want to display the outputs from the P4API while it is running commands.
I can see that the P4API.net has a P4Callbacks class, with several delegates: InfoResultsDelegate, TaggedOutputDelegate, LogMessageDelegate, ErrorDelegate.
My question is: How can I use those, I could not find a single example online of that. A short example code would be amazing !
Note: I am quite a beginner and have never used delegates before.
Answering my own questions by an example. I ended up figuring out by myself, it is a simple event.
Note that this only works with P4Server. My last attempt at getting TaggedOutput from a P4.Connection was unsuccessful, they were never triggered when running a command.
So, here is a code example:
P4Server p4Server = new P4Server(syncPath);
p4Server.TaggedOutputReceived += P4ServerTaggedOutputEvent;
p4Server.ErrorReceived += P4ServerErrorReceived;
bool syncSuccess = false;
try
{
P4Command syncCommand = new P4Command(p4Server, "sync", true, syncPath + "\\...");
P4CommandResult rslt = syncCommand.Run();
syncSuccess=true;
//Here you can read the content of the P4CommandResult
//But it will only be accessible when the command is finished.
}
catch (P4Exception ex) //Will be caught only when the command has completely failed
{
Console.WriteLine("P4Command failed: " + ex.Message);
}
And the two methods, those will be triggered while the sync command is being executed.
private void P4ServerErrorReceived(uint cmdId, int severity, int errorNumber, string data)
{
Console.WriteLine("P4ServerErrorReceived:" + data);
}
private void P4ServerTaggedOutputEvent(uint cmdId, int ObjId, TaggedObject Obj)
{
Console.WriteLine("P4ServerTaggedOutputEvent:" + Obj["clientFile"]);
}
I have a simple WPF application. The application records an RTSP stream to a file. For this purpose Vlc.DotNet library is used.
I have tested the application with two computers and the results are the same for both.
The application code is given below.
public partial class MainWindow : Window
{
private IPath _pathWrapper;
private IDirectoryInfo _vlcLibDirectory;
private VlcMediaPlayer _videoRecorder;
public MainWindow()
{
InitializeComponent();
}
private void OnButtonClick(object sender, RoutedEventArgs e)
{
if (_videoRecorder != null && _videoRecorder.IsPlaying())
{
_videoRecorder.Stop();
Button.Background = Brushes.Blue;
_videoRecorder = null;
return;
}
string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
_pathWrapper = new PathWrap();
_vlcLibDirectory = new DirectoryInfoWrap(_pathWrapper.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
var options = new string[]
{
"--file-logging",
"--logfile=OnvifVideoRecording.log",
"-vvv"
};
_videoRecorder = new VlcMediaPlayer(_vlcLibDirectory.DirectoryInfo, options);
//string fileDestination = "\\\\\\BuildSrv\\Videos\\A, A, 1\\test.mp4";
string fileDestination = #"D:\Media\Video\A, A, 1\test.mp4";
if (File.Exists(fileDestination))
{
File.Delete(fileDestination);
}
string[] mediaOptions =
{
":sout=#file{dst='" + fileDestination + "'}",
":sout-keep"
};
_videoRecorder.SetMedia("rtsp://192.168.1.110:5504/channel=0,stream=0", mediaOptions);
_videoRecorder.Play();
Button.Background = Brushes.Red;
}
}
The application has a window. The window has a button. When this button is pressed for the first time, recording a video file is started and the button turns red. I usually record video files for 10 minutes. When the button is pressed for the second time, recording a video file is stopped and the button turns blue.
If I record a file to the local destination (to the same computer where the program is run, for example, D:\Media\Video\A, A, 1\test.mp4), everything is ok. Recording video file is started and stopped quickly, almost immediately.
The problems occur when I try to record a file to the remote computer (for example, \BuildSrv\Videos\A, A, 1\test.mp4). Recording a video file starts immediately. However, _videoRecorder.Stop() takes approximately 30 seconds – 1 minute. Resource monitor shows very high network use (90% in case of one computer and 100% in case of another) after the button is pressed for the second time (recording video is stopped). The longer the recorded video file is, the more time is needed to stop VlcMediaPlayer.
Why does stopping VlcMediaPlayer takes so much time in case of recording an RTSP stream to the remote computer? Can this problem be solved somehow?
I've been looking into this for awhile now as I have created a client I would love to be able to run in a separate window (In a similar design to the Blizzard launcher or the old Ijji reactor). I was wondering if this was possible. Last week I created a web browser within Visual Basic but I was not happy with the final result at the bars where still stationed around the window. Any helpful tips or advice would be appreciated!
You didn't specify language, so you get it in c#. This might work. Starts chrome in app mode. here is the argument list
http://peter.sh/experiments/chromium-command-line-switches/
url = "--app=http://google.com";
Process[] pname = Process.GetProcessesByName("chrome");
if (pname.Length == 0)
{
chrome = false;
}
else // if chrome is running
{
if (!chrome)
{
Process process = new Process();
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = url;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
//Process.Start("chrome", url);
}
chrome = true;
}
I'm hoping someone can help me with this. I have found the examples for recording audio using XNA in a Silverlight application. And it works, however, only the first time in. I have all the recording functionality on a seperate WP7 Page and with successive visits to the page it doesn't work. The best I can tell is the microphone.start is getting called but the micophone.status remains stopped. What is weird is the BufferReady keeps getting called and the code within that function is all running but without the microphone really starting nothing is really happening. When you exit the app and come back in again the first time visit to the page and everything works fine, but a revisit to the page and it doesn't.
void microphone_BufferReady(object sender, EventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
{
microphone.GetData(buffer);
stream.Write(buffer, 0, buffer.Length);
TimeSpan tsTemp = timer.Elapsed;
TextBlockSeconds.Text = tsTemp.Hours.ToString().PadLeft(2, '0') + ":" + tsTemp.Minutes.ToString().PadLeft(2, '0') + ":" + tsTemp.Seconds.ToString().PadLeft(2, '0');
if(timer.Elapsed.Seconds >5)
DoStop();
});
}
private void ButtonRecord_Click(object sender, RoutedEventArgs e)
{
DisableRecordButton();
timer = new Stopwatch();
timer.Start();
stream = new MemoryStream();
TextBlockSeconds.Text = "00:00:00";
TextBlockStatus.Text = "Recording: ";
microphone.BufferDuration = TimeSpan.FromMilliseconds(500);
buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
microphone.Start();
}
private void DoStop()
{
if (timer.IsRunning)
timer.Stop();
if (microphone.State == MicrophoneState.Started)
{
microphone.Stop();
TextBlockStatus.Text = "Stopped: Ready to save";
}
else
{
TextBlockStatus.Text = "Ready: ";
}
TextBlockSeconds.Text = string.Empty;
EnableRecordButton();
}
Update...
I found the problem but no solution. I was calling the microphone.stop via code on a timer (so I could limit the recorded audio to 5 seconds). Exact same code to execute when a manual stop button would be clicked. When clicking the manual stop button everything worked fine, could re-visit the page and all would be fine. When the stop was called in code from the timer, next visit to the page would not work. So I implemented it with only a manual stop button but really would have been nice to do it automatically (and to know what the real issue was).
actually when you are navigating away from the page you can add
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
this.MicroPhone.BufferReady -= this.Microphone_BufferReady;
}
and when you are returning to page add
this.MicroPhone.BufferReady += this.Microphone_BufferReady;
You can add this statement either in a page loaded event or an OnNavigatedTo event
Added string name = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() to make sure that it was on the same thread (and it was).
But finally worked this out, the problem is the microphone.stop doesn't stop the microphone from continuing to fire the buffer ready event (like I was expecting). And it would seem the way the page is cached this causes some weird problems with that event still firing. So I added the code
microphone.BufferReady -= new EventHandler<EventArgs>(microphone_BufferReady);
to my code for stopping, and it all works now.
I can't see from your code how you're stopping the timer/microphone if you navigate away from the page and don't manually stop it.
If that's not it, are you ensuring that all your microphone operations are being executed on the same thread? (Just a thought.)