// prepare batch for processing private float[] PrepareInputs(int count) { // define overlap if (m_position >= count) { m_position -= (int)(float)(count * 0.5); } // Set Label if (m_wavReader != null && m_wavReader.HasTranscription) { char c = m_wavReader.GetTranscription((int)m_position, (int)m_position + count); int index = StringToDigitIndexes(c); Array.Clear(Owner.Label.Host, 0, Owner.Label.Count); // if unknown character, continue without setting any connection Owner.Label.Host[index] = 1.00f; Owner.Label.SafeCopyToDevice(); } // if input is corpus, cycle files in the set float[] result = new float[count]; if (Owner.InputType == InputTypeEnum.UserDefined && Owner.m_InputPathCorpus != "") { bool eof = (m_position + count < m_InputData.Length)?false: true; for (int i = 0; i < count; i++) { result[i] = (float)m_InputData[m_position]; m_position = ++m_position % m_InputData.Length; } if (eof) { m_position = 0; m_wavReader = new WavPlayer(audio[m_currentCorpusFile]); AttachTranscriptFileIfExists(audio[m_currentCorpusFile]); if (m_currentCorpusFile + 1 < audio.Length) { m_currentCorpusFile++; } else { m_currentCorpusFile = 0; } m_InputData = m_wavReader.ReadShort(m_wavReader.m_length); } } else // if input is single audio, cycle the file itself { for (int i = 0; i < count; i++) { result[i] = (float)m_InputData[m_position]; m_position = ++m_position % m_InputData.Length; } } return(result); }
public void CanDispose() { WavPlayer fileExist = new WavPlayer(fileName); WavPlayer fileEmpty = new WavPlayer(""); Assert.True(fileExist.Dispose()); Assert.True(fileEmpty.Dispose()); }
public void CanPlayWavAudioFile() { WavPlayer success = new WavPlayer(fileName); WavPlayer fail = new WavPlayer(""); Assert.True(success.Play()); Assert.False(fail.Play()); }
// Use this for initialization void Start() { if (new System.Random().Next(1, 3) == 1) { WavPlayer.PlayWavSound(Application.streamingAssetsPath + "/VoicePackets/远山/远山_交谈1.wav"); } else { WavPlayer.PlayWavSound(Application.streamingAssetsPath + "/远山_标题.wav"); } //print(Application.dataPath+ @"/StreamingAssets/VoicePackets/远山/远山_交谈1.wav"); //Debug.LogWarning("ShowTitle123123123"); }
/// <summary> /// Initializes a new instance of the <see cref="MainViewModel"/> class /// </summary> /// <param name="navigation"> /// Navigation instance /// </param> public MainViewModel(INavigation navigation) { Navigation = navigation; PlayCommand = new Command(async() => { _isPlaying = true; _cts = new CancellationTokenSource(); _audioStreamPolicy = new AudioStreamPolicy(AudioStreamType.Media); PlayCommand.ChangeCanExecute(); CancelCommand.ChangeCanExecute(); try { await WavPlayer.StartAsync(ResourcePath.GetPath("test.wav"), _audioStreamPolicy, _cts.Token); } catch (TaskCanceledException) { Tizen.Log.Info("WavPlayer", "A task for playing media was canceled."); } finally { _isPlaying = false; _cts?.Dispose(); _audioStreamPolicy?.Dispose(); } PlayCommand.ChangeCanExecute(); CancelCommand.ChangeCanExecute(); }, CanPlay); CancelCommand = new Command(() => { if (_isPlaying) { _cts?.Cancel(); _isPlaying = false; } PlayCommand.ChangeCanExecute(); CancelCommand.ChangeCanExecute(); }, CanCancel); }
private static void Main(string[] args) { UDPListener _udpListener = new UDPListener(8888); Thread thread = new Thread(_udpListener.StartListener); thread.Start(); //var sineWaveProvider = new SineWaveProvider32(); //sineWaveProvider.SetWaveFormat(16000, 1); // 16kHz mono //sineWaveProvider.Frequency = 2000; //sineWaveProvider.Amplitude = 0.25f; //var waveOut = new WaveOut(); //waveOut.Init(sineWaveProvider); //waveOut.Play(); WavPlayer wav = new WavPlayer(); wav.Play("../../resources/pampampam.wav"); UDPSender _udpSender = new UDPSender("127.0.0.1", 20381, 8888); _udpSender.ContiniousRandomDataSend(); }
void MouseDown() { //print(Application.streamingAssetsPath + "/VoicePackets/远山/远山_" + tmp.ElementAt(i) + ".wav"); //Debug.LogWarning(Application.streamingAssetsPath + "/VoicePackets/远山/远山_" + tmp.ElementAt(i) + ".wav"); //if (File.Exists(Application.streamingAssetsPath + "/VoicePackets/远山/远山_" + tmp.ElementAt(i) + ".wav")) //WavPlayer.PlayWavSound(Application.streamingAssetsPath + "/VoicePackets/远山/远山_" + tmp.ElementAt(i) + ".wav"); //else // print("无此音频文件!"); int len = list.Count(); int pos = new System.Random().Next(0, len); string str = (list.ElementAt(pos))[0]; string text = (list.ElementAt(pos))[1]; string filepath = Application.streamingAssetsPath + "/VoicePackets/远山/远山_" + str + ".wav"; if (File.Exists(filepath)) { WavPlayer.PlayWavSound(filepath); TextTest.text = text; countnum = 0; } //WavPlayer.PlayWavSound(Application.streamingAssetsPath + "/VoicePackets/远山/远山_问候.wav"); }
public static void SetWavPlayer(WavPlayer wp) { ControlPanel.wp = wp; }
void init() { Settings settings = Settings.GetInstance(); settings.LoadSettings(); ItemCombiner.ApplySettings(); WavPlayer.ApplySettings(); Form1.ApplySettings(); wp = new WavPlayer(this); wp.PlayReachedBy += new WavPlayer.ProcessEventHandler(this.ReportReceived); this.KeyPreview = true; ItemCombiner.SetWavPlayer(wp); GraphPanel.SetFont(defaultFont); ItemSet.SetWavPlayer(wp); ItemSet.SetForm(this); ControlPanel.SetFont(defaultFont); ControlPanel.SetWavPlayer(wp); cp = new ControlPanel(); baseTablePanel.Controls.Add(cp, 1, 1); }
public override void Execute() { if (SimulationStep == 0) { #region First step init m_position = 0; Owner.Features.Fill(0); Owner.Label.Fill(0); try { // load input data on simulation start switch (Owner.m_UserInput) { case InputTypeEnum.SampleSound: m_wavReader = new WavPlayer(GoodAI.SoundWorld.Properties.Resources.Digits_en_wav); m_wavReader.m_SamplesPerSec = 32000; m_wavReader.AttachTranscription(GoodAI.SoundWorld.Properties.Resources.Digits_en_txt); m_InputData = m_wavReader.ReadShort(m_wavReader.m_length); break; case InputTypeEnum.UserDefined: // reading corpus files if (Owner.m_InputPathCorpus != "") { audio = Directory.GetFiles(Owner.m_InputPathCorpus, "*.wav"); m_wavReader = new WavPlayer(audio[m_currentCorpusFile]); AttachTranscriptFileIfExists(audio[m_currentCorpusFile]); m_currentCorpusFile = 1; m_InputData = m_wavReader.ReadShort(m_wavReader.m_length); } else { m_wavReader = new WavPlayer(Owner.m_InputPathAudio); AttachTranscriptFileIfExists(Owner.m_InputPathAudio); m_InputData = m_wavReader.ReadShort(m_wavReader.m_length); } break; } } catch (Exception) { MyLog.ERROR.WriteLine("Not a valid sound device!"); } #endregion } if (SimulationStep % ExpositionTime == 0) { #region Every time step if (m_InputData == null) { return; } int size = 0; float[] result = new float[Owner.FeaturesCount]; // process data according to chosen feature type switch (Owner.FeaturesType) { case FeatureType.Samples: result = PrepareInputs(Owner.FeaturesCount); break; case FeatureType.FFT: // input size must be power of 2 and double sized due to the mirror nature of FFT size = NextPowerOf2(Owner.FeaturesCount * 2); result = PerformFFT(PrepareInputs(size)); //result = PerformFFT(GenerateSine(size)); // generate a test sine signal break; case FeatureType.MFCC: result = WindowFunction.Hanning(PrepareInputs(256)); result = PerformFFT(result); result = MFCC.Compute(result, player.m_SamplesPerSec, Owner.FeaturesCount); break; case FeatureType.LPC: result = WindowFunction.Hanning(PrepareInputs(256)); result = LPC.Compute(result, Owner.FeaturesCount); break; } #endregion // flush processed features into GPU Array.Clear(Owner.Features.Host, 0, Owner.Features.Count); for (int i = 0; i < Owner.FeaturesCount; i++) { Owner.Features.Host[i] = result[i]; } Owner.Features.SafeCopyToDevice(); } }
public override void Init(Int32 nGPU) { // init wavPlayer with memory stream m_stream = new MemoryStream(); player = new WavPlayer(m_stream); }
public static void MciStopRing(string fileName) { //只会响一遍 WavPlayer.mciStop(fileName); }
void Panic() { VIBRATEMOTOR(); WavPlayer.StartAsync(ResourcePath.GetPath("your_temperature_is_high.wav"), new AudioStreamPolicy(AudioStreamType.Alarm)); }
public static void Main(string[] args) { WavPlayer.Init(WavProvider); WavPlayer.Play(); Keyboard = new WindowsKeyController(keyMap.ToDictionary(kvp => (int)kvp.Key, kvp => (int)kvp.Value)); Mouse = new WindowsMouseController(mouseMap.ToDictionary(kvp => (int)kvp.Key, kvp => (int)kvp.Value)); Builder = new GameBuilder(); Builder.GameEngine(new FixedTickEngine(TPS)) .GameView(new GameView2D(ScreenWidth, ScreenHeight, Scale, Scale, Color.DarkSlateGray)) .GameFrame(new GameFrame(new AvaloniaWindowBuilder(), 0, 0, ScreenWidth, ScreenHeight, Scale, Scale)) .Controller(Keyboard) .Controller(Mouse) .Build(); Engine = Builder.Engine; GameFrame frame = Builder.Frame; AvaloniaWindow window = frame.Window as AvaloniaWindow; Referee = new Referee(); Engine.TickEnd += Referee.Tick; Sprites(); Rules(); SetupLevels(); SetupTitleScreen(); Engine.TickEnd += (s, gs) => { if (Iframe > 0) { Iframe--; } if (Program.Keyboard[(int)Actions.ESCAPE].IsPress()) { Program.WavPlayer.Stop(); Program.WavProvider.RemoveAllMixerInputs(); StopMovingWindow(); SetupTitleScreen(); } if (Program.Keyboard[(int)Actions.DIAGS].IsPress()) { ShowDiags = !ShowDiags; } if (Program.Keyboard[(int)Actions.RESTART].IsPress()) { if ((Program.Referee.OutofControl || Program.Level == 7) && !Engine.Location.GetEntities <Banner>().Any()) { return; } if (Engine.Location.GetEntities <Banner>().FirstOrDefault()?.Text == "you win") { if (Level == -1) { for (int i = 0; i < 10; i++) { Referee.AddRule(Rule.GetNameRandomRule()); } } else { Level++; } } StopMovingWindow(); Program.WavPlayer.Stop(); Program.WavProvider.RemoveAllMixerInputs(); // Levels can call the reset with something different Referee.ResetTimer(); switch (Level) { case -1: SetupCrazyMode(); break; case 0: break; case 8: SetupCredits(); Level = 9; break; case 9: if (CreditsFinished) { SetupThanksForPlaying(); Level = 10; } break; case 10: SetupTitleScreen(); break; default: if (CreditsFinished) { StartingLevel = Level; Levels[Level - 1].SetupLevel(); } break; } if (Program.Diff == Difficulty.NORMAL && Level == 7) { Lives = 3; } else if (Program.Diff == Difficulty.EASY && Level == 7) { Lives = 4; } else { Lives = 1; } } }; Engine.Start(); while (true) { } }
public void PlayWav(string name) { WavPlayer.Open(new Uri("Wav/" + name + ".wav", UriKind.Relative)); WavPlayer.Play(); }