Exemple #1
0
        private static void speak(Speech speech)
        {
            try
            {
                proc = new Process();
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow  = true;
                proc.StartInfo.FileName        = executable;
                string voice()
                {
                    switch (speech.gender)
                    {
                    case Gender.Male: return("-voice rms");

                    case Gender.Female: return("-voice slt");

                    case Gender.Neutral: return("-voice ap");

                    default: return("");
                    }
                }
                proc.StartInfo.Arguments = $"{GetSpeedArg()} {GetPitchArg()} {voice()} -t " + "\"" + speech.text.Replace('"', '\'') + "\"";
                //ModEntry.Log("mimic args: " + proc.StartInfo.Arguments);
                proc.Start();
                ModEntry.Log("speaking '" + speech.text + "'");
            }
            catch (Exception e)
            {
                ModEntry.Log("Failed Text2Speech: " + e.Message, StardewModdingAPI.LogLevel.Error);
                proc = null;
            }
        }
Exemple #2
0
        public static void Init()
        {
            initialized = false;
            switch (StardewModdingAPI.Constants.TargetPlatform)
            {
            case StardewModdingAPI.GamePlatform.Android:
                ModEntry.Log("Android detected. Speech2Text is not supported.", StardewModdingAPI.LogLevel.Error);
                break;

            case StardewModdingAPI.GamePlatform.Linux:
                if (ModEntry.GetConfig().tts_path.Length > 0)
                {
                    if (System.IO.File.Exists(ModEntry.GetConfig().tts_path))
                    {
                        executable  = ModEntry.GetConfig().tts_path;
                        initialized = true;
                        ModEntry.Log("Using custom tts installation specified in config.json", StardewModdingAPI.LogLevel.Debug);
                    }
                    else
                    {
                        ModEntry.Log("Couldn't find specified tts installation '" + ModEntry.GetConfig().tts_path + "' from config.json", StardewModdingAPI.LogLevel.Error);
                    }
                }
                else if (System.IO.File.Exists(linux_mimic_std))
                {
                    executable  = linux_mimic_std;
                    initialized = true;
                    ModEntry.Log("Using system mimic installation", StardewModdingAPI.LogLevel.Debug);
                }
                else
                {
                    string path = ModEntry.GetHelper().DirectoryPath + "/" + linux_mimic_manual_install;
                    if (System.IO.File.Exists(path))
                    {
                        executable  = path;
                        initialized = true;
                        ModEntry.Log("Using mimic installation in mod folder", StardewModdingAPI.LogLevel.Debug);
                    }
                    else
                    {
                        ModEntry.Log("Couldn't find mimic installation at " + linux_mimic_std + " or in mod folder", StardewModdingAPI.LogLevel.Error);
                    }
                }
                break;

            case StardewModdingAPI.GamePlatform.Mac:
                ModEntry.Log("OSX detected. Speech2Text is not supported.", StardewModdingAPI.LogLevel.Error);
                break;

            case StardewModdingAPI.GamePlatform.Windows:
                ModEntry.Log("Windows detected. Speech2Text is not supported.", StardewModdingAPI.LogLevel.Error);
                break;
            }
            if (initialized)
            {
                queueTask.Start();
            }
        }
Exemple #3
0
        private static void PlaySoundEffect(string name, Vector2 sourcePosition)
        {
            int pX = (int)Game1.player.Position.X / Game1.tileSize;
            int pY = (int)Game1.player.Position.Y / Game1.tileSize;
            int sX = (int)sourcePosition.X / Game1.tileSize;
            int sY = (int)sourcePosition.Y / Game1.tileSize;

            float GetVolume()
            {
                float d = 1 - Utility.distance(pX, sX, pY, sY) / hearing_distance;

                return(d < 0 ? 0 : (d > 1 ? 1 : d));
            }

            float GetPitch()
            {
                if (pY == sY)
                {
                    return(0);
                }
                if (pY > sY)
                {
                    return(-(float)System.Math.Min((pY - sY), hearing_distance) / hearing_distance);
                }
                else
                {
                    return((float)System.Math.Min((sY - pY), hearing_distance) / hearing_distance);
                }
            }

            float GetPan()
            {
                if (pX == sX)
                {
                    return(0);
                }
                if (pX > sX)
                {
                    return(-(float)System.Math.Min((pX - sX), hearing_distance) / hearing_distance);
                }
                else
                {
                    return((float)System.Math.Min((sX - pX), hearing_distance) / hearing_distance);
                }
            }

            SoundEffectInstance instance = soundEffects[name];

            instance.Pan    = GetPan();
            instance.Volume = GetVolume();
            instance.Pitch  = GetPitch();
            ModEntry.Log($"pitch " + instance.Pitch);
            instance.Play();
        }
Exemple #4
0
        private static void PlaySound(string cueName, Vector2 sourceTilePos)
        {
            try
            {
                SoundBank soundBank = ModEntry.GetHelper().Reflection.GetField <SoundBank>(Game1.soundBank as SoundBankWrapper, "soundBank").GetValue();

                Cue           cue      = soundBank.GetCue(cueName);
                AudioListener listener = new AudioListener
                {
                    Position = new Vector3(Game1.player.Position, 0)
                };
                AudioEmitter emitter = new AudioEmitter
                {
                    Position = new Vector3(sourceTilePos * Game1.tileSize, 0)
                };

                cue.Apply3D(listener, emitter);
                cue.Play();
            }
            catch (System.Exception e)
            {
                ModEntry.Log("Error while playing sound: " + e.Message);
            }
        }
Exemple #5
0
        private static BarrierType FindBarrierType()
        {
            Vector2 nextPos = PlayerNextPosition();

            xTile.Dimensions.Location location = new xTile.Dimensions.Location((int)nextPos.X, (int)nextPos.Y);
            Vector2      tilePos = new Vector2(location.X / Game1.tileSize, location.Y / Game1.tileSize);
            GameLocation loc     = Game1.currentLocation;

            Layer buildingsLayer = loc.map.GetLayer("Buildings");
            Tile  tile           = buildingsLayer.PickTile(location, Game1.viewport.Size);

            if (tile != null)
            {
                int i = tile.TileIndex;
                ModEntry.Log("tile " + tile.TileIndex);
                if (loc is FarmHouse)
                {
                    return(BarrierType.Housewall);
                }
                else if (i == 184 || i == 1183 || i == 1210 || i == 211 || i == 183 || i == 1182 || i == 185 || i == 1184 || i == 235 || i == 1290 || i == 260 || i == 1315 ||
                         i == 259 || i == 258 || i == 1257 || i == 1207 || i == 208 || i == 213 || i == 212 || i == 1232 || i == 233 || i == 1209 || i == 210 || i == 238 || i == 1292 ||
                         i == 237 || i == 1291)
                {
                    return(BarrierType.Water);
                }
                else if (i == 383 || i == 384 || i == 385 || i == 436 || i == 411 || i == 386 || i == 434 ||
                         i == 832 || i == 833 || i == 834 || i == 866 || i == 898 || i == 930 || i == 900 || i == 929 || i == 928 || i == 896 || i == 864)
                {
                    return(BarrierType.Fence);
                }
                else if (i == 541 || i == 542 || i == 543 || i == 544 || i == 391 || i == 416 || i == 441 || i == 466 || i == 491 || i == 516 || i == 419 || i == 394 || i == 444 ||
                         i == 469 || i == 494 || i == 519 || i == 422 || i == 438 || i == 540 || i == 439 || i == 464 || i == 440 || i == 467 || i == 468 || i == 369 ||
                         i == 344 || i == 319 || i == 294 || i == 295 || i == 291 || i == 316 || i == 366 || i == 496 || i == 522 || i == 548 || i == 547 || i == 546 ||
                         i == 545 || i == 539 || i == 371 || i == 399 || i == 446 || i == 290)
                {
                    return(BarrierType.Cliff);
                }
                else if (i == 1938 || i == 1939)
                {
                    return(BarrierType.PetWaterBowl);
                }
                else if (i == 40 || i == 72 || i == 322 || i == 323 || i == 327 || i == 54 || i == 86)
                {
                    return(BarrierType.Bench);
                }
                else if (i == 1003)
                {
                    return(BarrierType.Lantern);
                }
                return(BarrierType.UnknownWall);
            }
            else if (loc.isTerrainFeatureAt((int)tilePos.X, (int)tilePos.Y))
            {
                TerrainFeature terrainFeature = loc.terrainFeatures.ContainsKey(tilePos) ? loc.terrainFeatures[tilePos] : loc.getLargeTerrainFeatureAt((int)tilePos.X, (int)tilePos.Y);
                //ModEntry.Log("terrain: "+terrainFeature.ToString());
                if (terrainFeature is Bush)
                {
                    return(BarrierType.Bush);
                }
                if (terrainFeature is Tree)
                {
                    return(BarrierType.Tree);
                }
                return(BarrierType.UnknownTerrain);
            }

            /*
             * else if (Game1.currentLocation.getLargeTerrainFeatureAt(location.X / Game1.tileSize, location.Y / Game1.tileSize) != null)
             * {
             *  ModEntry.Log("large terrain");
             *  return BarrierType.UnknownLargeTerrain;
             * }
             */
            else if (Game1.currentLocation.getObjectAtTile(location.X / Game1.tileSize, location.Y / Game1.tileSize) is StardewValley.Object obj && obj != null)
            {
                switch (obj.ParentSheetIndex)
                {
                case 294:
                case 295:
                    return(BarrierType.Wood);

                case Object.mineStoneSnow1:
                case Object.mineStoneSnow2:
                case Object.mineStoneSnow3:
                case Object.mineStonePurpleSnowIndex:
                case Object.mineStoneRed1Index:
                case Object.mineStoneRed2Index:
                case Object.mineStoneBlue1Index:
                case Object.mineStoneBlue2Index:
                case Object.mineStoneGrey1Index:
                case Object.mineStoneGrey2Index:
                case Object.mineStoneBrown1Index:
                case Object.mineStoneBrown2Index:
                case Object.mineStoneMysticIndex:
                case Object.mineStonePurpleIndex:
                case 343:
                case 450:
                    return(BarrierType.Stone);

                //case Object.mineStoneSnow1
                case 674:
                case 675:
                case 784:
                case 792:
                    return(BarrierType.Weed);

                default:
                    ModEntry.Log("obj: " + obj.Name + ", id: " + obj.ParentSheetIndex);
                    return(BarrierType.UnknownObject);
                }
            }