An warware: yadda ake nema akan wikipedia tare da magana da sakamakon

A duniyar fasaha, neman bayanai akan intanit ya zama wani muhimmin bangare na rayuwarmu ta yau da kullun. Tare da gidajen yanar gizo marasa adadi da ke ba da ilimi kan batutuwa masu tarin yawa, Wikipedia ษ—aya ce irin wannan dandali da ke aiki a matsayin babban kundin sani. Tambayar ta taso - ta yaya za mu iya bincika yadda ya kamata a kan Wikipedia kuma a bayyana sakamakon da babbar murya? A cikin wannan labarin, za mu bincika mafita ga wannan matsala, bayanin mataki-mataki na lambar Python, da zurfafa zurfin cikin ษ—akunan karatu da ayyukan da aka yi amfani da su.

Don magance wannan batu, za mu ฦ™irฦ™iri rubutun Python wanda zai ษ—auki tambayar bincike, za mu debo bayanan da suka dace daga Wikipedia, sannan mu karanta taฦ™aitaccen sakamakon. Za a cimma wannan ta amfani da dakunan karatu na Wikipedia da pyttsx3. Bari mu nutse cikin bayanin mataki-mataki na lambar.

Mataki na farko shine shigar da ษ—akunan karatu da ake buฦ™ata, waษ—anda za'a iya yin su ta amfani da pip:

pip install wikipedia
pip install pyttsx3

Wikipedia Library

The Laburaren Wikipedia Python wrapper ne don API na Wikipedia. Yana ba mu damar cirewa bayanai da taฦ™aitawa daga labaran Wikipedia, bincika labarai, har ma da fassara labarai. A cikin rubutun mu, za mu yi amfani da wikipedia.search() da wikipedia.summary() ayyuka don nemo batun da ake so da kuma kawo taฦ™aicensa.

Pyttsx3 Library

The pyttsx3 library (gajeren sigar Python Text-to-Speech 3) ษ—akin karatu ne wanda ke ba da damar aikin rubutu-zuwa-magana a Python. Yana da dandamali-mai zaman kansa kuma yana aiki tare da Windows da macOS. Wannan ษ—akin karatu baya buฦ™atar haษ—in Intanet kuma yana dacewa da Python 2 da Python 3. A cikin rubutun mu, za mu yi amfani da pyttsx3.init() da pyttsx3.say() ayyuka don fara injin rubutu-zuwa-magana da magana taฦ™aice daga Wikipedia.

Bayanin Code

Tare da shigar da ษ—akunan karatu da ake buฦ™ata, yanzu za mu iya ci gaba da rubuta rubutun mu na Python:

import wikipedia
import pyttsx3

# Initialize the text-to-speech engine
engine = pyttsx3.init()

# Take the search query as input and search on Wikipedia
query = input("Enter the topic to search on Wikipedia: ")
results = wikipedia.search(query)

# Print the search results
print("Search results:")
for result in results:
    print(result)

# Choose the desired result, fetch the summary, and speak it
choice = input("Enter the name of the article you want to get the summary for: ")
summary = wikipedia.summary(choice)
engine.say(summary)
engine.runAndWait()

A cikin rubutun, mun fara shigo da dakunan karatu da ake buฦ™ata (wikipedia da pyttsx3) kuma mu fara injin rubutu-zuwa-magana. Sai mu tambayi mai amfani tambayar tambayar su, yi amfani da wikipedia.search() aiki don bincika batun akan Wikipedia, da nuna sakamakon. Mai amfani zai iya zaษ“ar sakamakon da ake so, kuma mun kawo taฦ™aitawar ta amfani da wikipedia.summary() aiki. A ฦ™arshe, muna amfani da pyttsx3.ce() da kuma pyttsx3.runAndWait() ayyuka don yin magana taฦ™aice.

Tare da wannan rubutun, yanzu zaku iya nemo kowane batu akan Wikipedia kuma ku sami taฦ™aitaccen bayanin da babbar murya ta amfani da shi Python, ษ—akin karatu na Wikipedia, da pyttsx3. Neman farin ciki!

Shafi posts:

Leave a Comment