头部的Angular Dynamic meta标签(Angular Dynamic meta tags in head)
我需要在角度应用程序的特定页面上插入打开的图形元标记。
这些标签根据页面所具有的新闻或视频而不同。
我试图向$ rootscope添加一个变量。 这个变量在相关时会被元标记填充。
现在这是我的问题。 只要这个变量被HTML字符串填充,它们不会构成头部的一部分,而是输出到身体。 我搜索了一天,找不到任何可行的解决方案。 任何帮助,将不胜感激
I need to insert open graph meta tags on a particular page in an angular app.
These tags are different based on the news or video that the page has.
I tried adding a variable to the $rootscope. This variable will be populated with the meta tags when it is relevant.
Now here is my issue. As soon as this variable gets populated with the HTML string, they don't form a part of the head and are instead outputted to the body. I have searched for a day and could not find any viable solutions. Any help would be appreciated
原文:https://stackoverflow.com/questions/27381918
最满意答案
终于在我挠了头两天之后我终于做到了。 对于那些想要实现这样的但却无法实现的人来说,这里是代码
public void speak(final String talk) throws InterruptedException { final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int ringVolume = audioManager .getStreamVolume(AudioManager.STREAM_RING); int musicVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); currentRingVolume = ringVolume; musicVolume = (int) ((musicVolume * seekbarValue) / 100); if (PauseRingtone == true) { audioManager.setStreamVolume(AudioManager.STREAM_RING, 1, AudioManager.FLAG_SHOW_UI); } else { audioManager.setStreamVolume(AudioManager.STREAM_RING, ringVolume, AudioManager.FLAG_SHOW_UI); } audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0); int result = tts .setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onStart(String utteranceId) { // TODO Auto-generated method stub } @Override public void onError(String utteranceId) { // TODO Auto-generated method stub } @Override public void onDone(String utteranceId) { // TODO Auto-generated method stub System.out.println("done"); audioManager.setStreamVolume(AudioManager.STREAM_RING, currentRingVolume, 0); } }); HashMap<String, String> params = new HashMap<String, String>(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "stringId"); tts.speak(talk, TextToSpeech.QUEUE_FLUSH, params); System.out.println("speaking after tts is over" + talk + " " + result); }
解释: -
ringVolume
- 获取手机中设置的铃声 .ie铃声音量的当前音量。
musicVolume
- 获取当前音乐的音量
currentRingVolume
只保留ringVolume
。注意 -
STREAM_RING
和STREAM_MUSIC
是不同的东西。 看到现在基本的想法是在
TTS
讲话时将ringtone
mute
,然后将其设置为之前的值。
seekBarValue
- 是我的SeekBar
,它描绘了音乐音量的TTS
音量,是可选的。
PauseRingtone
- 是一个CheckBox Preference
,用于检查我们是否要在讲话时暂停铃声。 如果为true
则将AudioManager.STREAM_RING
设置为1
即vibrate
其他ringVolume
即Phone Value
,因此TTS
和Ringtone
播放。audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,musicVolume, 0)
将
TTS
的音量设置为musicVolume
。 在TTS
完成发言之后,即在onDone()
我们使用currentRingVolume
将Ringtone
的音量设置回ringVolume
。如果我的回答有助于标记我的答案有用。
Finally after scratching my head for two days i finally did it. For all those who want to implement something like this but are unable to do so here is the code
public void speak(final String talk) throws InterruptedException { final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int ringVolume = audioManager .getStreamVolume(AudioManager.STREAM_RING); int musicVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); currentRingVolume = ringVolume; musicVolume = (int) ((musicVolume * seekbarValue) / 100); if (PauseRingtone == true) { audioManager.setStreamVolume(AudioManager.STREAM_RING, 1, AudioManager.FLAG_SHOW_UI); } else { audioManager.setStreamVolume(AudioManager.STREAM_RING, ringVolume, AudioManager.FLAG_SHOW_UI); } audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0); int result = tts .setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onStart(String utteranceId) { // TODO Auto-generated method stub } @Override public void onError(String utteranceId) { // TODO Auto-generated method stub } @Override public void onDone(String utteranceId) { // TODO Auto-generated method stub System.out.println("done"); audioManager.setStreamVolume(AudioManager.STREAM_RING, currentRingVolume, 0); } }); HashMap<String, String> params = new HashMap<String, String>(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "stringId"); tts.speak(talk, TextToSpeech.QUEUE_FLUSH, params); System.out.println("speaking after tts is over" + talk + " " + result); }
explaination :-
ringVolume
- gets the current volume of the ringtone .i.e ringtone volume set in the phone.
musicVolume
- gets the current volume of the music
currentRingVolume
just retains theringVolume
.Note-
STREAM_RING
andSTREAM_MUSIC
are different things. SeeNow the basic idea is to
mute
theringtone
whileTTS
is speaking and then set it to previous value.
seekBarValue
- is mySeekBar
which depicts the level of theTTS
volume w.r.tmusicVolume
and is optional.
PauseRingtone
- is aCheckBox Preference
which checks whether we want to pause ringtone while speaking. Iftrue
is sets theAudioManager.STREAM_RING
to1
i.e.vibrate
elseringVolume
i.e.Phone Value
, so bothTTS
andRingtone
play at the same time.audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,musicVolume, 0)
sets the volume of
TTS
tomusicVolume
. AfterTTS
has completed speaking i.e. inonDone()
we set the volume ofRingtone
back to theringVolume
usingcurrentRingVolume
.If my answer helped mark my answer useful.
相关问答
更多-
看来你想要的是不可能的。 根据MSDN上的这个帖子,无法获得铃声列表: 应用无法访问现有铃声或提醒音; 但是,您的应用可以保存媒体文件以用作铃声... It seems what you want is not possible. According to this thread on MSDN it is not possible to get a list of ringtones: An app cannot access existing ringtone or alert sounds; howe ...
-
我使用下面的代码得到了解决方案: 内部onActivityResult: Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); Ringtone r=RingtoneManager.getRingtone(this, uri); String ringToneName=r.getTitle(this)); Toast.makeText(getApplicationContext(), "Ringtone ...
-
Android:在设置>声音和显示>手机铃声中看不到铃声(Android: Ringtone is not visible in settings>Sound and Display>phone ringtone)[2024-04-27]
如果铃声包含名为“铃声”的文件夹,则会从系统铃声目录以及SD卡中提取铃声列表。 所以你可以尝试做的是同时将你的音板中的铃声复制到SD卡,进入一个名为“铃声”的文件夹(首先检查文件夹是否已经存在),同时设置铃声。 The list of ringtones is pulled from the system ringtones directory, as well as from the SD Card, if it contains a folder named "ringtones". So what y ... -
获取一个MP3库,为您提供声音大小的反馈 (像winamp中的均衡器一样) 将此幅度标准化为[0,1]的标度 由于android振动器api仅支持振动持续时间(非强度),因此需要将此幅度离散化为0或1(持续时间较短)。 如果声音的大小小于某个值0.5,则不要在该持续时间内振动。 否则会震动。 Get an MP3 library that gives you feedback for magnitude of sound (Something like equalizer in winamp) Normal ...
-
尝试改变: speakOut(); promptSpeechInput(); 至 promptSpeechInput(); 然后添加: speakOut(); 后 eText1.setText(result.get(0)); 这应该在文本完成后才能说出来 编辑:使用此选项确定语音何时结束。 当它只是调用promptSpeechInput()时 Try changing: speakOut(); promptSpeechInput(); to promptSpeechInput(); And th ...
-
在通过文本到语音说话然后恢复时暂停手机铃声(Pause Phone Ringtone while Speaking through Text To Speech and then Resume)[2024-03-27]
终于在我挠了头两天之后我终于做到了。 对于那些想要实现这样的但却无法实现的人来说,这里是代码 public void speak(final String talk) throws InterruptedException { final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int ringVolume = audioManager .g ... -
您可以做的是在段落之间短暂停顿并在此暂停期间收听用户命令。 要实现它,您需要使用UtteranceProgressListener 。 说出一段然后在onDone打开语音识别器。 设置倒数计时器并onFinish关闭语音识别器并阅读下一段。 What you can do is having a short pause between paragraphs and listen to user commands during this pause. To implement it you need to u ...
-
通常,如果divice进入睡眠状态,则代码不会运行。 为了使代码运行,您需要从PowerManager获取WakeLock 。 但在你的情况下,你不需要一直获得WakeLock。 你需要每10分钟唤醒一次你的应用程序。 否则你的应用程序只会吃电池什么也不做。 为了定期唤醒您的应用程序,您需要使用特殊的Android的AlarmManager 。 这是一个例子: Intent myIntent = new Intent(getApplicationContext(), YourActivity.class); ...
-
只需进行一些更改,我就可以修复您的示例。 首先,我在try-catch块的开头添加了这些行: System.setProperty("FreeTTSSynthEngineCentral", "com.sun.speech.freetts.jsapi.FreeTTSEngineCentral"); System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDir ...
-
由于TextToSpeech类没有暂停/恢复方法,我建议执行以下操作: 1)将书分成句子而不是500个字符块。 (您可以使用“。”作为分隔符进行解析)。 2)引入一个“主索引”计数器X,它跟踪进度:我们在句子#X /总句子。 3)当用户点击暂停时,只需使用stop()方法。 4)当用户点击恢复时,在被中断的句子的开头恢复语音。 无论如何,这将导致更好的用户理解(书中),而不是字面上暂停和恢复句子。 Since the TextToSpeech class doesn't have pause/resume ...