//------------------------------------------------------------------------------- public static void Start() { sounds = new Dictionary <string, SoundEffect>(); // allows to pause and stop songs = new Dictionary <string, Song>(); BuildAudioLibrary(AudioContent.SoundString()); BuildSongLibrary(AudioContent.SongString()); AudioContent.Start(); }
public void WavFile() { var content = new AudioContent(@"Assets/Audio/blast_mono.wav", AudioFileType.Wav); Assert.AreEqual(@"Assets/Audio/blast_mono.wav", content.FileName); Assert.AreEqual(AudioFileType.Wav, content.FileType); Assert.IsNull(content.Identity); Assert.AreEqual(0, content.LoopStart); Assert.AreEqual(315970, content.LoopLength); Assert.AreEqual(71640000, content.Duration.Ticks); var format = content.Format; Assert.IsNotNull(format); Assert.AreEqual(1, format.Format); Assert.AreEqual(1, format.ChannelCount); Assert.AreEqual(44100, format.SampleRate); Assert.AreEqual(88200, format.AverageBytesPerSecond); Assert.AreEqual(2, format.BlockAlign); Assert.AreEqual(16, format.BitsPerSample); Assert.IsNotNull(format.NativeWaveFormat); Assert.AreEqual(18, format.NativeWaveFormat.Count); using (var reader = new BinaryReader(new MemoryStream(format.NativeWaveFormat.ToArray()))) { var formatType = reader.ReadInt16(); var channels = reader.ReadInt16(); var sampleRate = reader.ReadInt32(); var averageBytesPerSecond = reader.ReadInt32(); var blockAlign = reader.ReadInt16(); var bitsPerSample = reader.ReadInt16(); var zero = reader.ReadInt16(); Assert.AreEqual(format.Format, formatType); Assert.AreEqual(format.ChannelCount, channels); Assert.AreEqual(format.SampleRate, sampleRate); Assert.AreEqual(format.AverageBytesPerSecond, averageBytesPerSecond); Assert.AreEqual(format.BlockAlign, blockAlign); Assert.AreEqual(format.BitsPerSample, bitsPerSample); Assert.AreEqual(0, zero); } var data = content.Data; Assert.NotNull(data); Assert.AreEqual(631940, data.Count); // Seems like XNA just let the Data property throw // an exception after it has been disposed. content.Dispose(); Assert.Throws <InvalidContentException>(() => { var temp = content.Data; }); }
static void Main() { // If using Professional version, put your serial key below. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); var presentation = new PresentationDocument(); // Create new presentation slide. var slide = presentation.Slides.AddNew(SlideLayoutType.Custom); // Create and add audio content. AudioContent audio = null; using (var stream = File.OpenRead("Applause.wav")) audio = slide.Content.AddAudio(AudioContentType.Wav, stream, 2, 2, LengthUnit.Centimeter); // Set the ending fade durations for the media. audio.Fade.End = TimeOffset.From(300, TimeOffsetUnit.Millisecond); // Get the picture associated with this media. var picture = audio.Picture; // Set drawing properties. picture.Action.Click.Set(ActionType.PlayMedia); picture.Layout.Width = Length.From(7, LengthUnit.Centimeter); picture.Layout.Height = Length.From(7, LengthUnit.Centimeter); picture.Name = "Applause.wav"; // Create and add video content. VideoContent video = null; using (var stream = File.OpenRead("Wildlife.wmv")) video = slide.Content.AddVideo("video/x-ms-wmv", stream, 10, 2, 10, 5.6, LengthUnit.Centimeter); // Set drawing properties. video.Picture.Action.Click.Set(ActionType.PlayMedia); video.Picture.Name = "Wildlife.wmv"; // Set the amount of time to be trimmed from the start and end of the media. video.Trim.Start = TimeOffset.From(600, TimeOffsetUnit.Millisecond); video.Trim.End = TimeOffset.From(800, TimeOffsetUnit.Millisecond); // Set the starting and ending fade durations for the media. video.Fade.Start = TimeOffset.From(100, TimeOffsetUnit.Millisecond); video.Fade.End = TimeOffset.From(200, TimeOffsetUnit.Millisecond); // Add video bookmarks. video.Bookmarks.Add(TimeOffset.From(1500, TimeOffsetUnit.Millisecond)); video.Bookmarks.Add(TimeOffset.From(3000, TimeOffsetUnit.Millisecond)); presentation.Save("Audio and Video.pptx"); }
public void Mp3File() { var content = new AudioContent(@"Assets/Audio/rock_loop_stereo.mp3", AudioFileType.Mp3); Assert.AreEqual(@"Assets/Audio/rock_loop_stereo.mp3", content.FileName); Assert.AreEqual(AudioFileType.Mp3, content.FileType); Assert.IsNull(content.Identity); Assert.AreEqual(0, content.LoopStart); Assert.AreEqual(0, content.LoopLength); Assert.AreEqual(79930000, content.Duration.Ticks); var format = content.Format; Assert.IsNotNull(format); Assert.AreEqual(1, format.Format); Assert.AreEqual(2, format.ChannelCount); Assert.AreEqual(44100, format.SampleRate); Assert.AreEqual(176400, format.AverageBytesPerSecond); Assert.AreEqual(4, format.BlockAlign); Assert.AreEqual(16, format.BitsPerSample); Assert.IsNotNull(format.NativeWaveFormat); Assert.AreEqual(18, format.NativeWaveFormat.Count); using (var reader = new BinaryReader(new MemoryStream(format.NativeWaveFormat.ToArray()))) { var formatType = reader.ReadInt16(); var channels = reader.ReadInt16(); var sampleRate = reader.ReadInt32(); var averageBytesPerSecond = reader.ReadInt32(); var blockAlign = reader.ReadInt16(); var bitsPerSample = reader.ReadInt16(); var zero = reader.ReadInt16(); Assert.AreEqual(format.Format, formatType); Assert.AreEqual(format.ChannelCount, channels); Assert.AreEqual(format.SampleRate, sampleRate); Assert.AreEqual(format.AverageBytesPerSecond, averageBytesPerSecond); Assert.AreEqual(format.BlockAlign, blockAlign); Assert.AreEqual(format.BitsPerSample, bitsPerSample); Assert.AreEqual(0, zero); } // For MP3 it seems the data is never availble. Assert.Throws <InvalidContentException>(() => { var data = content.Data; }); // Seems like XNA just let the Data property throw // an exception after it has been disposed. content.Dispose(); Assert.Throws <InvalidContentException>(() => { var temp = content.Data; }); }
public override SoundEffectContent Process(AudioContent input, ContentProcessorContext context) { // Fallback if we aren't buiding for iOS. var platform = ContentHelper.GetMonoGamePlatform(); if (platform != MonoGamePlatform.iOS) { return(base.Process(input, context)); } var targetSampleRate = input.Format.SampleRate; // XNA SoundEffects have their sample rate changed based on the quality setting on the processor. //http://blogs.msdn.com/b/etayrien/archive/2008/09/22/audio-input-and-output-formats.aspx switch (this.Quality) { case ConversionQuality.Best: break; case ConversionQuality.Medium: targetSampleRate = (int)(targetSampleRate * 0.75f); break; case ConversionQuality.Low: targetSampleRate = (int)(targetSampleRate * 0.5f); break; } targetSampleRate = Math.Max(8000, targetSampleRate); var wavStream = new MemoryStream(); WaveFormat outputFormat = AudioConverter.ConvertFile(input.FileName, wavStream, AudioFileType.Wav, targetSampleRate, input.Format.BitsPerSample, input.Format.ChannelCount); var outputData = new ReadOnlyCollection <byte>(wavStream.ToArray()); wavStream.Close(); var waveFormatHeader = writeWavHeader(outputFormat); // SoundEffectContent is a sealed class, construct it using reflection var type = typeof(SoundEffectContent); ConstructorInfo c = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(ReadOnlyCollection <byte>), typeof(ReadOnlyCollection <byte>), typeof(int), typeof(int), typeof(int) }, null); var outputSoundEffectContent = (SoundEffectContent)c.Invoke(new Object[] { waveFormatHeader, outputData, input.LoopStart, input.LoopLength, (int)input.Duration.TotalMilliseconds }); return(outputSoundEffectContent); }
public void Compile() { ParsedPath wavFileName = Target.InputFiles.Where(f => f.Extension == ".wav").First(); ParsedPath xnbFileName = Target.OutputFiles.Where(f => f.Extension == ".xnb").First(); WavFile wavFile = WavFileReader.ReadFile(wavFileName); AudioContent ac = new AudioContent(wavFile); if (!Directory.Exists(xnbFileName.VolumeAndDirectory)) { Directory.CreateDirectory(xnbFileName.VolumeAndDirectory); } XnbFileWriterV5.WriteFile(ac, xnbFileName); }
IEnumerator GoogleTextToSpeech(string sourceText, Action <string> callbackContent) { // Create json object TTSRequestBody tts = new TTSRequestBody() { input = new Input() { text = sourceText }, voice = new Voice() { languageCode = "en-US", ssmlGender = "FEMALE" }, audioConfig = new AudioConfig() { audioEncoding = "LINEAR16" } }; string requestBody = JsonUtility.ToJson(tts); Debug.Log("[TextToSpeech] request body json: " + requestBody); string requestUri = $"https://texttospeech.googleapis.com/v1beta1/text:synthesize?key={APIKey}"; //Debug.Log("[TextToSpeech] request uri: " + requestUri); using (UnityWebRequest uwr = UnityWebRequest.Post(requestUri, "")) { uwr.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(requestBody)); yield return(uwr.SendWebRequest()); if (uwr.isNetworkError) { Debug.Log(uwr.error); } else { string responseBody = uwr.downloadHandler.text; Debug.Log("[TextToSpeech] response body json: " + responseBody); AudioContent ac = JsonUtility.FromJson <AudioContent>(responseBody); callbackContent?.Invoke(ac.audioContent); } } }
void SetupAudioContent() { foreach (Transform child in container.transform) { Destroy(child.gameObject); } foreach (string audioPath in selectedUnit.audioFiles) { GameObject audioButton = Instantiate(buttonPrefab, container.transform); AudioContent audioContent = audioButton.GetComponent <AudioContent>(); audioContent.label.text = audioPath; audioContent.clip = Resources.Load("Sounds/Units/" + game.selectedFaction.name + "/" + selectedRace.name + "/" + selectedUnit.name + "/" + selectedUnit.name + audioPath) as AudioClip; audioContent.audioSource = source; audioContent.Setup(); } }
public void ConvertAudio(string sourceFile, ConversionFormat format, ConversionQuality quality, int channels, int averageBytesPerSecond, int sampleRate, int bitsPerSample, int blockAlign) { var content = new AudioContent(sourceFile, AudioFileType.Wav); content.ConvertFormat(format, quality, null); Assert.AreEqual(ToWavFormat(format, content.Format.BitsPerSample), content.Format.Format); Assert.AreEqual(channels, content.Format.ChannelCount); Assert.AreEqual(bitsPerSample, content.Format.BitsPerSample); // TODO: We don't quite match right with XNA on these. // We should look to fix this for 100% compatibility. if (format != ConversionFormat.Adpcm) { Assert.AreEqual(sampleRate, content.Format.SampleRate); Assert.AreEqual(averageBytesPerSecond, content.Format.AverageBytesPerSecond); Assert.AreEqual(blockAlign, content.Format.BlockAlign); } content.Dispose(); }
private IEnumerator GetAudioFile(WWW outputData) { //get audio content (synthesis data) AudioContent aC = JsonUtility.FromJson <AudioContent>(outputData.text); string audioContent = aC.audioContent; //create audio file using (Stream audioStream = File.Create("Assets/Resources/AudioFile.mp3")) { yield return(audioStream); //fill audio file with audio content (synthesis data) byte[] audioContentArray = System.Convert.FromBase64String(audioContent); BinaryWriter binaryWriter = new BinaryWriter(audioStream); binaryWriter.Write(audioContentArray, 0, audioContentArray.Length); // appear text on screen and play audio file StartCoroutine(ShowTextAndPlayAudioFile()); } // yield return null; }
private void InsertAudioContents() { ReportStart(_cache.AudioContent, "Audio Content"); var currentProgress = 0; foreach (var item in _cache.AudioContent) { var entity = new Entity.tAudioContent() { Content = item, }; _context.tAudioContent.Add(entity); AudioContent.Add(item, entity); IncreaseCurrent(ref currentProgress); } ReportFinish(); }
private void FillAudioHashes(IEnumerable <Profiler.AudioTrack> audioTracks) { if (audioTracks == null) { return; } var valid = audioTracks.Where(IsNotNull); foreach (var audioTrack in valid) { AudioContent.Add(audioTrack.Content); if (!string.IsNullOrEmpty(audioTrack.Format)) { AudioFormat.Add(audioTrack.Format); } if (!string.IsNullOrEmpty(audioTrack.Channels)) { AudioChannels.Add(audioTrack.Channels); } } }
public override SongContent Process(AudioContent input, ContentProcessorContext context) { // Fallback if we aren't buiding for iOS. var platform = ContentHelper.GetMonoGamePlatform(); if (platform != MonoGamePlatform.iOS && platform != MonoGamePlatform.Linux) { return(base.Process(input, context)); } //TODO: If quality isn't best and it's a .wma, don't compress to MP3. Leave it as a .wav instead string outputType = (platform == MonoGamePlatform.iOS) ? "mp3" : "wav"; string outputFilename = Path.ChangeExtension(context.OutputFilename, outputType); string directoryName = Path.GetDirectoryName(outputFilename); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } var inputFilename = Path.GetFullPath(input.FileName); // XNA's songprocessor converts the bitrate on the input file based // on it's conversion quality. //http://blogs.msdn.com/b/etayrien/archive/2008/09/22/audio-input-and-output-formats.aspx int desiredOutputBitRate = 0; switch (this.Quality) { case ConversionQuality.Low: desiredOutputBitRate = 96000; break; case ConversionQuality.Medium: desiredOutputBitRate = 128000; break; case ConversionQuality.Best: desiredOutputBitRate = 192000; break; } AudioFileType target = (platform == MonoGamePlatform.iOS) ? AudioFileType.Mp3 : AudioFileType.Wav; // Create a new file if we need to. FileStream outputStream = input.FileType != target ? new FileStream(outputFilename, FileMode.Create) : null; if (input.FileType != target) { AudioConverter.ConvertFile(inputFilename, outputStream, target, desiredOutputBitRate, input.Format.BitsPerSample, input.Format.ChannelCount); } else { File.Copy(inputFilename, outputFilename, true); } if (outputStream != null) { outputStream.Close(); } context.AddOutputFile(outputFilename); // SoundEffectContent is a sealed class, construct it using reflection var type = typeof(SongContent); ConstructorInfo c = type.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(int) }, null); var outputSongContent = (SongContent)c.Invoke(new Object[] { Path.GetFileName(outputFilename), (int)input.Duration.TotalMilliseconds }); return(outputSongContent); }